Forum Discussion
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.
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);
- devnyk10 years agoNew Contributor
That exactly is my constraint. I cannot have all the scripts marked as "USEUNIT" in the driver.
Given there will be 1000+ test scripts, it wont be advisable to import all the test scripts in the driver. It will heavily increase the memory footprint of the program, and also will become difficult for maintenance as the project grows. The above proposed solution is exactly what I am willing to do, but with USEUNIT <scriptname>.
Could you suggest a solution to achieve anything equivalant to "USEUNIT <scriptname>" where scriptname is a variable
- joseph_michaud10 years ago
Staff
Keep in mind that all the script units in the project are being processed every time you run a test. They are all 'loaded' whether or not you reference them or use them. To see this, try placing a Log.Message() call in a script unit outside of a function. It will get called every time any test is run.
Regardless, as you pointed out earlier, you don't need the USEUNIT statement when using Runner.CallMethod(). And it doesn't matter which variables you use to hold the list of script units to use.
Using a simple JScript array:
function RunSomeTestsA() { var unitlist = ["Unit1", "Unit2"]; for (var i = 0; i < unitlist.length; i++) { Runner.CallMethod(unitlist[i] + ".test"); } }Using a project temporary table variable:
function RunSomeTestsB() { // https://support.smartbear.com/viewarticle/73562/ "Variables of the Table Type" if (!Project.Variables.VariableExists("MyTable")) { Project.Variables.AddVariable("MyTable", "Table"); } var t = Project.Variables.VariableByName("MyTable"); t.AddColumn("Unit"); t.RowCount = 2; t.Unit(0) = "Unit1"; t.Unit(1) = "Unit2"; for (var i = 0; i < t.RowCount; i++) { Runner.CallMethod(t.Unit(i) + ".test"); } }