Data Driven Suites
This section describes using Sahi's inbuilt data driven suite mechanism.
Introduction
info
Sahi Pro provides support for Data Driven Suites from version v5.1 onwards.
Data Driven suites (also referred to as ddcsv) can be used to
- run scripts, suites, test_case csv and other data driven suites files
- pass arguments to functions defined in Sahi scripts
- tag scripts/suites and run selective scripts/suites based on those tags
- control the execution of scripts/suites/csv depends upon other scripts/suites/csv status
Structure
| A | B | C | D | E | F | G | H | |
| 1 | #script | url | tags | depends | prerequisites | timeout_minutes | Argument1 | Argument2 |
| 2 | ScriptName.sah | StartURL | "tag1,tag2" | Browser | 5 | Argument1_Value | Argument2_Value | |
| 3 | ScriptName1.sah | StartURL | "tag1,tag2" | ScriptName.sah | Windows | 10 | Argument1_Value | Argument2_Value |
Structure Explained
ddcsv can be used to run the same script file with different sets of arguments. eg. invalidLogin.sah in the example above.| A | B | C | D | E | F | G | H | |||
| 1 | #script | url | tags | depends | prerequisites | timeout_minutes | username | password | empId | Header Row |
| 2 | login.sah | http://sahi.co.in/demo/training/login.htm | user,high | Browser | 5 | test | secret | 12345 | ||
| 3 | invalidLogin.sah | http://sahi.co.in/demo/training/login.htm | user,medium | login.sah | Browser | 10 | test | s1234 | 46789 | |
| 4 | ||||||||||
| 5 | #script | url | tags | username | password | Header Row | ||||
| 6 | invalidLogin.sah | http://sahi.co.in/demo/training/login.htm | user,medium | aa | dd | |||||
| 7 | ||||||||||
| 8 | #script | Header Row | ||||||||
| 9 | scriptWithoutTags.sah | |||||||||
| 10 | ||||||||||
| 11 | #script | tags | depends | Header Row | ||||||
| 12 | parent.dd.csv | admin,high | ||||||||
| 13 | ddcsv.dd.csv | user | parent.dd.csv | |||||||
| 14 | suiteInsideddcsv.suite | admin,high | PREV |
-
Header Rows give Sahi an outline format about the coming rows. They start with #script. There are 4 predefined header values.
Any other values in a Header Row are considered data variable names. Eg. username, password and empId are considered variable names.#script Signifies a new header row. The value under this column header is the name of the Sahi script to be run. url The start URL for the script tags Specifies the tags applicable to this script depends Specifies the scripts/suites/csv to which this scripts/suites/csv to be depended prerequisites Specifies the prerequisites required to run the script. Start mode is considered as one of the prerequisites for all the scripts specified in a suite.
To explain line 2,
2 login.sah http://sahi.co.in/demo/training/login.htm user,high test secret 12345 login.sahwill be executed with start URLhttp://sahi.co.in/demo/training/login.htmwith variables$username = "test"; $password = "secret"; $empId = "12345"; -
For any script, if the argument name, number of arguments or the order of arguments needs to be changed,
a new
#scriptrow needs to be added to specify the intended change to Sahi. This can be seen in line number 5, 8 and 11. eg. In line 3,
invalidLogin.sah username, password and empId are needed where as empId is not passed in line 6. So we need to add line number 5 to inform Sahi regarding this change.A B C D E F G H 1 #script url tags depends prerequisites timeout_minutes username password empId Header Row 2 login.sah http://sahi.co.in/demo/training/login.htm user,high Browser 5 test secret 12345 3 invalidLogin.sah http://sahi.co.in/demo/training/login.htm user,medium login.sah Browser 10 test s1234 46789 4 5 #script url tags username password Header Row 6 invalidLogin.sah http://sahi.co.in/demo/training/login.htm user,medium aa dd -
In line 9,
we have simply passed a script file without any other information. In this case start url is the base url passed to this dd.csv file while running. The base URL is specified in testrunner.bat or drun.bat. Running dd.csv files has been covered in the next topic.8 #script Header Row 9 scriptWithoutTags.sah -
Suites, test_case csv, and other data driven suites can also be invoked from dd.csv file. This is shown in above table (rows 11-14).
11 #script tags depends Header Row 12 parent.dd.csv admin,high 13 ddcsv.dd.csv user parent.dd.csv:SUCCESS 14 suiteInsideddcsv.suite admin,high PREV:ANY -
tags,url,depends,prerequisitesand any variables passed to a ddcsv file get cascaded to all ddcsvs and scripts inside it. For example, all scripts/ddcsvs insideparent.dd.csvwill also be assignedadminandhightags -
dependsis used to specify the name of the scripts/suites/csv to which the current script/suite/csv is dependent and the status to which it needs to be depends. Eglogin.sah:SUCCESSThe current script/suite/csv will start executing only if all the dependent scripts/suites/csv have executed completely. The script can start to execute or be moved to SKIPPED status depending on what status it depends on. If the dependent status is SUCCESS and if any of the depended scripts/suites/csv is FAILED or ABORTED or SKIPPED the current script will be moved to SKIPPED status. If the dependent status is not specified, by default it depends on SUCCESS status.PREVcommand can be used instead of mentioning the immediate previous script/suite/csv name.script:ANYimplies the script will execute irrespective of the dependent status once the dependent execution is completed.
Consider lines 12, 13 and 14, the parent.dd.csv:SUCCESS mentioned under depends column in line 13 indicate that the ddcsv.dd.csv is dependent on SUCCESS status of parent.dd.csv. So ddcsv.dd.csv will wait for the completion of parent.dd.csv and will start execution only if the status is SUCCESS. If any of the scripts inside parent.dd.csv is FAILED or ABORTED, ddcsv.dd.csv will not get executed and labeled as SKIPPED status. ThePREV:ANYcommand in the line 14 refers to ddcsv.dd.csv if the main suite executes with no tags. The suiteInsideddcsv.suite will start executing once ddcsv.dd.csv execution is completed irrespective of the status. If the main suite is executed with admin or high tag, thePREVcommand will be referred to parent.dd.csv as the ddcsv.dd.csv will not be considered for execution due to the tags mismatch. -
prerequisitesis used to specify the requirement of the script. In distributed playback, script will be run on that node only, which has all the specified capabilities to run the script.
Consider lines 2, login.sah requiresBROWSERmode to run the script.//specify multiple modes for a particular script. Browser,Android15 #script tags prerequisites Header Row 16 login.sah admin,high Browser,Android //specify multiple modes with the instances for a particular script. //here Android mode requires 2 device instances. Browser,Android:217 #script tags prerequisites Header Row 18 login.sah admin,high Browser,Android:2 //specify multiple browsers with the instances for a particular script. //here script requires 1 chrome instance and 2 firefox instances. chrome,firefox:219 #script tags prerequisites Header Row 20 login.sah admin,high chrome:1,firefox:2 //specify the node tags. //here script will run only on the node with "windows10" tag. windows1021 #script tags prerequisites Header Row 22 login.sah admin,high windows10 infoNote: one can set the node tags insahi.node.tagsinsahi.properties -
timeout_minutesis used to specify the maximum duration the script/suite can run. Sahi aborts the script/suite once the time is up.
In the example, if login.sah did not finish in 5 minutes, Sahi will abort the script and mark it as ABORTED_TIMEOUT.infoIf 'timeout' is provided for both suite and a script, Sahi aborts script when any of the time is elapsed firstRefer here to provide timeout for the whole suite execution.
info
script:ANY is introduced from Sahi Pro v11.0.0.8Data Driven Suites with testcases
warning
This feature was added to facilitate playback of only failed scenarios when running a failed scripts suite.
The
From Sahi Pro V6.2.0 onwards, along with three predefined header values (#script, url, tags) the testcases column is automatically added to the failed scripts suite.
It should not ideally be added or modified by testers in their original suites.
testcases header is also recognized.
Only those testcases which are specified in this column will run during playback.
For example,
test.dd.csv is a data driven suite.
| #script | url | tags | testcases |
| scenario.s.csv | http://sahitest.com/demo/ | auth | testLoginLogout |
| another.s.csv | http://sahitest.com/demo/ | admin |
Here's how
scenario.s.csv looks like.
| Comment | Tags | TestCase | Keyword | Argument1 | Argument2 | Argument3 |
| loadSahi | sample_lib.sah | |||||
| Simple test for adding books and verifying total | auth,bookspage | checkShoppingCartTotal | [Documentation] | Smoke test | ||
| login | test | secret | ||||
| addBooks | 3 | 2 | 1 | |||
| verifyTotal | 1650 | |||||
| logout | ||||||
| Test for login logout | auth | testLoginLogout | [Documentation] | Check Invalid | ||
| login | test | bad password | ||||
| logout |
testLoginLogout testcase will be run when the above test.dd.csv is executed. No other scripts or scenario files or testcases will be run.
infoIn scenario file, the column is
TestCase while in the data driven suite the column header is testcasesinfoSince
Sahi Pro v11.2.0, the suite.retry_only_failed_testcases_for_scenario property is introduced to include the testcases column header for the failed scripts suite of the scenario file in the data-driven suite. The default value is true. If property value is set to false, the testcases column header for the failed scripts suite of scenario file will not be included in the data-driven suite.warningSpecifying
testcases will cause the tags attribute to be ignored.
Testcases will run even if the tags are not matched.
Running Data Driven Suites
Data Driven Suites are run the same way as normal suites. They can be run from command prompt using testrunner or drun or ant the same way as .suite files are run. The steps to run a dd.csv file are mentioned below.- Open cmd prompt by clicking on the "bin" link on "Sahi Dashboard".
- Run the following cmd
or for distributed run:testrunner sahitests/ddcsv/test.dd.csv http://sahi.co.in/demo/ ie "admin||medium"drun demo/ddcsv/test.dd.csv http://sahi.co.in/demo/ ie "admin||medium"
The parameters passed in the above commands are explained below:
Note: If the user specifies the last parameter as "admin&&medium" script files associated with BOTH the tags will run i.e. none of the scripts in the above example.sahitests/ddcsv/test.dd.csv path and file name of Data Driven Suite http://sahi.co.in/demo/ Start URL ie browser on which the scripts will run "admin||medium" This specifies the tags and hence the scripts that need to be run. Here scipts on line 3,6,12,14 will run.
Variable $isDataPassed and _isDataPassed()
Along with user defined variables, Sahi passes a variable named$isDataPassed to the script with value true if user variables are passed to script.
$isDataPassed is useful during development of scripts which take arguments.
When scripts are played back from Sahi Controller, arguments can not be passed to the script file.
In such cases, default values of variables can be defined as given below.
if(typeof $isDataPassed == "undefined"){
// entered if executed from Controller
// NOT entered if run from dd.csv
$username = "default_name";
$password = "default_pwd";
}
// or
if(!_isDataPassed()){
// entered if executed from Controller
// NOT entered if run from dd.csv
$username = "default_name";
$password = "default_pwd";
}
A script with the above code behaves thus:
- if it is run from the Controller,
$isDataPassedwill beundefinedand_isDataPassed()will returnfalse. So theifblock will be executed and$usernameand$passwordwill be assigned"default_name"and"default_pwd"respectively. - if it is run from a
dd.csvfile,$isDataPassedand_isDataPassed()will betrue. So theifblock will not be executed.