Groovy script to read test case name in parasoft

SrivasS5SrivasS5 Posts: 10

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.


  • jakubiakjakubiak Posts: 684 admin

    Are you doing this from an Extension Tool?

  • jakubiakjakubiak Posts: 684 admin
    edited November 2017

    If you are doing it from an Extension Tool, you can use a script like the following:

    import com.parasoft.api.*;
    public void printName(Object input, Context context) {
        Application.showMessage("test name: " + context.getContextName());
  • SrivasS5SrivasS5 Posts: 10

    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);

    return runFolder;


  • jakubiakjakubiak Posts: 684 admin
    edited November 2017

    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:

    def Name1=context.getContextName();
    Application.showMessage("test name: " + Name1);

    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.

  • bprabhbprabh Posts: 5

    is there a way to read the name of the scenario thats executing?

  • jakubiakjakubiak Posts: 684 admin

    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:

    import com.parasoft.api.*;
    import java.lang.*;
    public void printTestNames(Object obj, Context context) {
        Application.showMessage("top level scenario: " + getTopLevelScenarioName(context));
        Application.showMessage("parent scenario: " + getParentScenarioName(context));
    public void printContexts(Context context) {
        Application.showMessage("print all contexts");
        while (context != null) {
            Application.showMessage("    name: " + context.getContextName());
            Application.showMessage("    type: " + context.getContextType());
            context = context.getParentContext();
    public String getTopLevelScenarioName(Context context) {
        Context previous = null;
        while (context != null && !context.getContextType().equals("Application")) {
            previous = context;
            context = context.getParentContext();
        return previous != null ? previous.getContextName() : "";
    public String getParentScenarioName(Context context) {
        return context.getContext("TestSuite").getContextName();
  • goofy78270goofy78270 Posts: 97

    Sorry for the addition here, but I thought it fell in the same context.

    With the above, is it also possible to get the location of the testsuite (ie...${test_suite_loc})

  • benken_parasoftbenken_parasoft Posts: 908 ✭✭✭

    With the above, is it also possible to get the location of the testsuite

    I'm not sure if there's public (non-internal) scripting API to get this. The closest thing I found is this:
    com.parasoft.api.ScriptingContext.getAbsolutePathFile(String fileName).

    Passing "" or "." for the "fileName" should get you the folder containing the tst file but not the tst file itself. Otherwise, you can try putting ${test_suite_loc} in some field where it is likely get resolved in a way that you can read it later, like maybe on the Input tab of an Extension Tool.

Sign In or Register to comment.