Sahi Pro - 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
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
Structure
A | B | C | D | E | |
1 | #script | url | tags | Argument1 | Argument2 |
2 | ScriptName.sah | StartURL | "tag1,tag2" | 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 | ||
1 | #script | url | tags | username | password | empId | Header Row |
2 | login.sah | http://sahi.co.in/demo/training/login.htm | user,high | test | secret | 12345 | |
3 | invalidLogin.sah | http://sahi.co.in/demo/training/login.htm | user,medium | 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 | Header Row | ||||
12 | ddcsvInsideddcsv.dd.csv | admin,high | |||||
13 | ddcsv.dd.csv | user | |||||
14 | suiteInsideddcsv.suite | admin,high |
-
Header Rows give Sahi an outline format about the coming rows. They start with #script. There are 3 predefined header values.
#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
Any other values in a Header Row are considered data variable names. Eg. username, password and empId are considered variable names.
To explain line 2,
2 login.sah http://sahi.co.in/demo/training/login.htm user,high test secret 12345
login.sah
will be executed with start URLhttp://sahi.co.in/demo/training/login.htm
with 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#script
row 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,
A B C D E F 1 #script url tags username password empId Header Row 2 login.sah http://sahi.co.in/demo/training/login.htm user,high test secret 12345 3 invalidLogin.sah http://sahi.co.in/demo/training/login.htm user,medium 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
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.
-
In line 9,
8 #script Header Row 9 scriptWithoutTags.sah
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.
-
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 Header Row 12 ddcsvInsideddcsv.dd.csv admin,high 13 ddcsv.dd.csv user 14 suiteInsideddcsv.suite admin,high -
tags
,url
and any variables passed to a ddcsv file get cascaded to all ddcsvs and scripts inside it.
For example, all scripts/ddcsvs insideddcsvInsideddcsv.dd.csv
will also be assignedadmin
andhigh
tags
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 demo/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:
demo/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.
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.
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,
$isDataPassed
will beundefined
and_isDataPassed()
will returnfalse
.
So theif
block will be executed and$username
and$password
will be assigned"default_name"
and"default_pwd"
respectively. - if it is run from a
dd.csv
file,$isDataPassed
and_isDataPassed()
will betrue
.
So theif
block will not be executed.