Quantcast
Channel: New board topics in SmartBear Community
Viewing all articles
Browse latest Browse all 20990

Picking a random row from a dataset as part of a test

$
0
0

TestComplete has the ability to drive tests using a data source (Excel, CSV, datbase, etc), and there is a Data Loop option built in if you need to repeat the same steps for all the rows in a dataset.

  

Data Driving a Test Case in TestComplete

 

However, there may be times when you don't need to loop through all the data in a dataset and just want to pick one at random.  This is a guide showing an example using JScript.  Similar functionality is available for other scripting languages as well, with slightly different syntax.

 

 

1.) Define your data

 

You can use a pre-defined data source for this, or TestComplete's built-in data generation wizard.  In this case I'm using the data generation wizard to create 10,000 random names for me to pick from.  This creates a Table variable, and that can be stored in a single Keyword test or with an entire Project.

 

Data Generator Wizard

 

Data Generation Wizard2.png

 

2.) Create a second variable as an integer to store the random number

 

RandomNumberVariable.png

 

3.) In the test, use the Set Variable Value to assign that integer a random number between 1 and the total number of rows in that table.  In my case 10,000.  Use the Code Expression option for the mode.

 

This example works in JScript, if your Project is in another scripting language the syntax here would need to be adjusted.

 

SetVariableValue.png

 

4.) Use that integer variable to select a row of your table and return the value, that can be used in the test steps.

 

useintest.png

Related Forum Post:

Generating random string values (A - D) & select from dropdown

 

 

 

 

 


Viewing all articles
Browse latest Browse all 20990

Trending Articles