cancel
Showing results for 
Search instead for 
Did you mean: 

Executing a test item or keyword test from script, by name or index in a variable

SOLVED
Highlighted
Contributor

Executing a test item or keyword test from script, by name or index in a variable

Does anyone know if there is any way to run a Keyword or Test Item from code with a variable name or index?

 

I could not find any run methods associated with either.

 

The only way I can think of is to have a humongous Select statement specifying the individual keyword tests.

 

That's far from ideal from a maintenance point of view.

 

The reason for it allow a random test item to be run.

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Executing a test item or keyword test from script, by name or index in a variable

Hi,

 

eval() or evaluate() function (whatever is provided by scripting language your project is based on) might work for you.

Sample untested pseudocode:

var strTestName = 'Check_Pass';

var strTestString = 'KeywordTests.' + strTestName + '.Run();';

evaluate(strTestString);

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

5 REPLIES 5
Highlighted
Staff

Re: Executing a test item or keyword test from script, by name or index in a variable

def runKeywordTest():
KeywordTests.MyTestName.Run(parameters_if_any)
Best,
Justin Kim
Highlighted
Contributor

Re: Executing a test item or keyword test from script, by name or index in a variable

Thanks Justin,

 

The only problem with this is that MyTestName is hard coded.

 

Is there any way of making MyTestName a variable?

 

Otherwise it requires something like this....

 

switch ( Test_Caption )
{
case 'KeywordTests - Check_Pass':
KeywordTests.Check_Pass.Run;
break;

case 'KeywordTests - Check_Fail':
KeywordTests.Check_Fail.Run;
break;

case 'KeywordTests - Login Normal User':
KeywordTests.Login_and_verify_operator.Run();
break;
default:
Log.Warning("No test was found corresponding to :''" + Test_Caption + "''");

 

Highlighted
Staff

Re: Executing a test item or keyword test from script, by name or index in a variable

I think this may have to be a feature request then

I'm trying to understand where this would be helpful. To be able to invoke keyword tests as a part of your script routines, but only run certain keyword tests based on the variable we pass (which being the name of the specific keyword tests themselves)

I feel like there may already be ways around this in terms of grouping keyword tests for execution or for invoking other test items based on certain conditions. 

whether that be tag based executions of your tests from CICD, or from just simply creating a script routine that runs only a certain collection of keyword tests in a certain sequence... (just throwing ideas out here now)

Maybe if you elaborate on the use case (of what you're trying to achieve, end goal etc.) then some of the other members of the community can share their workarounds.

in the meanwhile ill play around with testcomplete a bit too, to see if this is feasible 

Best,
Justin Kim
Highlighted
Community Hero

Re: Executing a test item or keyword test from script, by name or index in a variable

Hi,

 

eval() or evaluate() function (whatever is provided by scripting language your project is based on) might work for you.

Sample untested pseudocode:

var strTestName = 'Check_Pass';

var strTestString = 'KeywordTests.' + strTestName + '.Run();';

evaluate(strTestString);

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

Highlighted
Contributor

Re: Executing a test item or keyword test from script, by name or index in a variable

That's it Alex!  

 

Thanks!!!

 

I knew there was a way of doing it but could not remember the function.  😅

 

The use case is to run random keyword functional tests from a suite of about 500.

 

We have daily tests that test critical functions but we'd like to add some randomness as an added confidence margin.  The TestComplete random number gen seems random enough. 🙂

 

You have just saved me from the headache of writing and maintaining a 500+ element switch-case structure.  Thanks again!

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors