Groovy script to read test case name in parasoft
Hi,
I am using groovy script for reading of parameter from the data source and creating of folder at the same location. I am able to do this much but now I want my folder name to be same as my test case name. Therefore can you please tell me what should be the groovy script **to read the **test case name from my test suite so that the folder could be created with the same name.
0
Answers
Are you doing this from an Extension Tool?
If you are doing it from an Extension Tool, you can use a script like the following:
hi,
Thanks for the script.
I used the same in my groovy script , but it is still not reading the test name from parasoft.
Please find my groovy script and please tell me what should I add to read the test name and create folder with the same name at the location provided in my data source.
import static java.util.Calendar.*;
import java.text.SimpleDateFormat;
import javax.xml.datatype.XMLGregorianCalendar;
import java.text.DateFormat;
import java.lang.String;
import java.util.regex.Pattern;
import java.sql.Timestamp;
import com.parasoft.api.*;
String path(input, context){
def sdf = new java.text.SimpleDateFormat("dd-MM-yyyy hh-mm-ss aa");
def SysDate = sdf.format( new Date()) ;
value = context.getValue("HeaderValues", "FolderPath")
def Name1=Application.showMessage("test name: " + context.getContextName());
String runFolder = value+Name1+SysDate;
def runFolderDir= new File(runFolder);
runFolderDir.mkdir();
return runFolder;
}
Your script is not quite correct - you are setting the value of "Name1" to the output of Application.showMessage() - which is a void function that doesn't return anything. Change that line to the following two lines:
context.getContextName() will give you the name of the test when running from an Extension Tool, but may not if you are running it from a script in a different tool. So if you're not using an Extension Tool, please let me know where you're inputting the script and I can help you modify it to get the test name.
is there a way to read the name of the scenario thats executing?
SOAtest scenarios are structured in a hierarchy of test suites (scenarios). You can use the Context objects to get information about them. Here is some code that will print out information that helps you to see how the contexts are structured, as well as methods that help you get the name for the parent test suite and the name for the top-level test suite. Put this code into an Extension Tool: