Forum Discussion

devnyk's avatar
devnyk
New Contributor
10 years ago

How to pass variables to USEUNIT command to dynamically load external script units

In my test project, All my test scripts have a method named "Test()" which perform the test activity.

I am currently working on creating a Driver script which will read the names of the script files to be executed from an excel file and then invoke TestcaseName.Test() method for all the script names returned from the excel file.

 

scriptName = ... read script names one by one from excel ...

strCommand = scriptName + ".Test"

Runner.CallMethod(strCommand);

 

This snippet is being iterated for all the script names returned by the excel file.

 

Currently, using the Runner.CallMethod, I am conveniently able to eliminate the need for having a "//USEUNIT <scriptname>" call. Since the Runner.CallMethod is deprecated, I am looking for an alternative method to iterate executing the Test() method for all the script files.

To achieve that, I am thinking of approach where I call the USEUNIT at runtime with the specific script name as a parameter. However, I am not able to pass a variable as a parameter to USEUNIT command. Could any of the experts help me resolve this problem?

How do I achieve this:

 

var scriptName = "TestScript_TC01"

//USEUNIT scriptName

 

 

Regards, Dev

  • Hi Dev,

     

    As you said, there is no way to pass a variable to USEUNIT. This statement is used to link script units inside a project.

     

    I can suggest that you store a script unit name in a project variable, and run the script execution by using the Exec method. Will this work for you?

     

    • devnyk's avatar
      devnyk
      New Contributor

      My requirement is to run only specific test scripts that are marked active in the Excelsheet. The challenge is that name of the script to be executed will become known only at the runtime.

       

      Will I be able to add the Script Unit Names fetched from excel to the Project Variables at Run time?

      I would appreciate if you could share some sample program of using combination of Project Variables and the Exec command as you suggested.

      • cunderw's avatar
        cunderw
        Community Hero

        Assuming you already have all of your useunits in your driver script you could do something like this:

         

        scriptName = ... read script names one by one from excel ...
        strCommand = scriptName + ".Test();"
        eval(strCommand);