Sahi Pro - Playback on Desktop
abstract
This section describes various ways of playing back Sahi scripts.
Playback via Sahi Controller
To playback via Controller, go to the Playback tab, choose the script to play and click "Play".As the script executes, Sahi will display the steps executed and also log them into a database.
You can view the logs by clicking on "Logs" link at the bottom of the Controller.
Playback via testrunner
testrunner.bat
and testrunner.sh
files allow running scripts from the command line.- Open a command prompt and cd to sahi/userdata/bin
(or click on the "Bin" link on the Sahi Dashboard)
- Run testrunner.bat to see the syntax
D:\sahi_pro\userdata\bin>testrunner
--
Usage: testrunnerFile path is relative to userdata/scripts
Multiple browsers can be specified using +. Eg. ie+firefox
tags are used only if the input suite is a csv file
--
Example:
testrunner demo/demo.suite http://sahi.co.in/demo/ firefox
testrunner demo/sahi_demo.sah http://sahi.co.in/demo/ ie
testrunner demo/sahi_demo.sah http://sahi.co.in/demo/ ie+firefox
testrunner demo/testcases/testcases_sample.csv http://sahi.co.in/demo/ ie "(user||admin)&&medium"
testrunner demo/ddcsv/test.dd.csv http://sahi.co.in/demo/ ie "(user||admin)&&medium"
--
D:\sahi_pro\userdata\bin> -
To run your suite, use,
You can specify the browser you want to run it on.C:\sahi\userdata\bin>testrunner.bat myapp.suite http://myappdomain/startpage.jsp firefox
-
Parameters other than suite, startURL and browserType can be modified by editing
testrunner.bat
-
To set the number of parallel browsers to execute the script in, modify
To run in one thread only, ie. to run scripts one after the other sequentially, useSET THREADS=5
SET THREADS=1
-
Sahi normally opens and closes the browser for each script.
To execute all scripts sequentially without closing and reopening browsers, use
SET THREADS=1 SET SINGLE_SESSION=true
-
Sahi, by default, writes logs to the database only.
To force it to write logs to the filesystem, use
html and xml logs will be created in theSET LOGS_INFO=html,xml
sahi/userdata/logs/playback
folder
To force it to write logs to specific file locations, use,
SET LOGS_INFO=html:D:/reports/htmllogs/,xml:D:/reports/xmllogs/
Output formats available are html,xml,junit,excel
The format to specify LOGS_INFO is
reportType1:filePath1,reportType2,reportType3:filePath3,...
-
When a Sahi suite is run, some scripts may fail because of environment reasons or due to browser crashes.
A natural next step for testers is to verify the failure by running the script again.
Sahi now automatically creates a suite of all failed scripts. The name of the failed suite has_failed
appended to the filename.
For example if you ran a suiteadmin/admin.suite
failed suite will be created asadmin/admin_failed.suite
Foradmin/admin.dd.csv
, it will beadmin/admin_failed.dd.csv
This failed suite file can then be run to verify only the failed testcases.
-
Sahi can send out emails at the end of a suite run.
Set the following properties in testrunner.bat file.
Email specific parameters like username, password etc. are defined inSET SEND_EMAIL_REPORT=true SET EMAIL_TRIGGER=success,failure SET EMAIL_PROPERTIES=email.properties SET EMAIL_PASSWORD_HIDDEN=true
sahi/userdata/bin/email.properties
file.
-
To set the number of parallel browsers to execute the script in, modify
info
Browser names are defined in sahi/userdata/browser-types-xml
testrunner.bat and testrunner.sh use the TestRunner java class internally.
testrunner.bat and testrunner.sh use the TestRunner java class internally.
Playback via ANT
Simple target
<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/>
<target name="failsahi" if="sahi.failed">
<fail message="Sahi tests failed!"/>
</target>
<target name="runbrowsertests">
<sahi suite="scripts/demo/demo.suite"
browserType="ie"
baseurl="http://machine_name/path/"
sahihost="localhost"
sahiport="9999"
failureproperty="sahi.failed"
haltonfailure="false"
threads="3"
>
</sahi>
<antcall target="failsahi"/>
</target>
info
NOTE:
- taskdef classpath is relative to where ant is run from
- sahi suite path is relative to sahi/userdata folder
Detailed target
<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/>
<target name="failsahi" if="sahi.failed">
<fail message="Sahi tests failed!"/>
</target>
<target name="runbrowsertests">
<sahi suite="scripts/demo/ddcsv/test.dd.csv"
browserType="ie"
baseurl="http://machine_name/path/"
sahihost="localhost"
sahiport="9999"
userdefinedid="sahi.co.in_firefox_english"
failureproperty="sahi.failed"
haltonfailure="false"
threads="3"
singlesession="false"
sendemail="true"
emailtrigger="success,failure"
emailproperties="email.properties"
emailPasswordHidden="true"
tags="(user||admin)&&medium"
>
<report type="html" logdir="D:/reports/htmllogs/"/>
<report type="junit"/>
</sahi>
<antcall target="failsahi"/>
</target>
info
NOTE:
- taskdef classpath is relative to where ant is run from
- sahi suite path is relative to sahi/userdata folder
- emailproperties path is relative where ant is run from
Attributes and their description
suite | Relative path to the suite file. It is relative to sahi/userdata folder. |
browserType | The browser on which the suite file plays back |
baseurl | Specifies URL which is the starting URL for all the scripts in the suite |
sahihost | Hostname of the server where Sahi is running (Can be IP as well) |
sahiport | Port on which Sahi is running |
userdefinedid | The unique id that the user can pass to differentiate a suite from other |
failureproperty | The property that gets set to false in case the build fails |
haltonfailure | Takes "true" or "false". Specifies if build should stop executing other tests if one test fails. |
threads | Number of simultaneous browser instances on which sahi tests will be run. |
singlesession | Takes "true" or "false". If "true", runs all scripts in a single browser without closing it between scripts. |
sendemail | Takes "true" or "false". If "true", Sahi sends an email summarizing the playback. |
emailtrigger | Takes "success" or "failure" or "success,failure". Triggers email in case of SUCCESS, FAILURE and both cases respectively. |
emailproperties | Relative path to the properties file that contains details about the mail viz. information about the sender, receiver, host, port, subject, content etc. Path is resolved relative to where this ant target is run from. |
emailPasswordHidden | Takes "true" or "false".If true, it hides the password from Sahi console and logs. |
tags | Optional. Used only for dd.csv and .csv suites. Tags are specified so that it is easy to choose which scripts/testcases to run. eg. in the target above, all the scripts which have 'medium' tag and 'admin' or 'user' (or both) tag will be run. |
Command to execute the above ANT target
ant -f demo.xml runbrowsertests
Distributed playback via drun
Sahi Pro can distribute and run tests on multiple machines (nodes).
drun.bat
(windows) and drun.sh
(linux) files allow running scripts on multiple machines from the command line.- Sahi distributes the scripts to different machines based on their capacity and availability of browsers. Please note that Sahi should be running on each of the nodes. Also, on each machine, the browser paths must be correctly specified.
- Open sahi_pro/userdata/bin/drun.bat (drun.sh on linux) using any editor.
-
Configure the NODES variable to contain all the machines on which the tests should run. The command to set the nodes in Windows and Linux respectively are:
For Windows:
For Linux:SET NODES=localhost:9999;othermachine:9999;thirdmachine:9999
export NODES=localhost:9999;othermachine:9999;thirdmachine:9999
-
When a Sahi suite is run, some scripts may fail because of environment reasons or due to browser crashes.
A natural next step for testers is to verify the failure by running the script again.
Sahi now automatically creates a suite of all failed scripts. The name of the failed suite has_failed
appended to the filename.
For example if you ran a suiteadmin/admin.suite
failed suite will be created asadmin/admin_failed.suite
Foradmin/admin.dd.csv
, it will beadmin/admin_failed.dd.csv
This failed suite file can then be run to verify only the failed testcases.
- Sahi can send a mail summarizing the playback. the variable SEND_EMAIL_REPORT can be set as true or false. If true, Sahi sends the mail. For Windows:
- Sahi can send a mail based on success or failure or in both the cases. This condition can be set using the EMAIL_TRIGGER variable. For Windows:
- The relative path to the properties file containing information about the mail such as sender, recipient, host, port etc. can be set using the EMAIL_PROPERTIES variable.
- Passwords can be hidden or shown from the console and logs by toggling the EMAIL_PASSWORD_HIDDEN variable.
It can be set as true or false. If true, Sahi hides the password from Sahi console and logs. - Sahi can set the logs to be generated in xml,html,junit,tm6 and excel types. The default type is html. For Windows:
- To execute the scripts using drun.bat, open a command window and go to the
/userdata/bin directory. This can also be done easily by clicking the bin link on the dashboard. - Run drun.bat to see the syntax.
- In the usage above, file path is always relative to userdata/scripts folder and tags will only be used when we are using a csv file as suite.
SET SEND_EMAIL_REPORT=true
For Linux:export SEND_EMAIL_REPORT=true
SET EMAIL_TRIGGER=success,failure
For Linux:export EMAIL_TRIGGER=success,failure
SET LOGS_INFO=xml,html
For Linux:export LOGS_INFO=xml,html
D:\sahi_pro\userdata\bin>drun
--
Usage: drun
File path is relative to userdata/scripts
Multiple browsers can be specified using +. Eg. ie+firefox
tags are used only if the input suite is a csv file
--
Example:
drun demo/demo.suite http://sahi.co.in/demo/ firefox
drun demo/sahi_demo.sah http://sahi.co.in/demo/ ie
drun demo/sahi_demo.sah http://sahi.co.in/demo/ ie+firefox
drun demo/testcases/testcases_sample.csv http://sahi.co.in/demo/ ie "(user||admin)&&medium"
drun demo/ddcsv/test.dd.csv http://sahi.co.in/demo/ ie "(user||admin)&&medium"
--
D:\sahi_pro\userdata\bin>
--
Usage: drun
Multiple browsers can be specified using +. Eg. ie+firefox
tags are used only if the input suite is a csv file
--
Example:
drun demo/demo.suite http://sahi.co.in/demo/ firefox
drun demo/sahi_demo.sah http://sahi.co.in/demo/ ie
drun demo/sahi_demo.sah http://sahi.co.in/demo/ ie+firefox
drun demo/testcases/testcases_sample.csv http://sahi.co.in/demo/ ie "(user||admin)&&medium"
drun demo/ddcsv/test.dd.csv http://sahi.co.in/demo/ ie "(user||admin)&&medium"
--
D:\sahi_pro\userdata\bin>
Distributed playback via ANT
Ant target
<target name="drun">
<tstamp>
<format property="ts" pattern="yyyy_MM_dd_HH_mm_ss" locale="en, IN"/>
</tstamp>
<property name="tempdest" value="temp/scripts/${ts}"/>
<property name="suite" value="demo/ddcsv/test.dd.csv"/>
<sahid suite="${tempdest}/${suite}"
baseurl="http://${urlbase}/demo/"
sahihost="localhost"
sahiport="9999"
failureproperty="sahi.failed"
haltonfailure="false"
browsertype="firefox"
sendEmail="false"
emailtrigger="success,failure"
emailProperties="email.properties"
emailPasswordHidden="true"
tags="(user||admin)&&medium"
originalSuitePath="scripts/${suite}"
>
<sync originFolder="userdata/scripts" destFolder="${tempdest}" ignorePattern=".*(svn|copied).*"/>
<node host="gramam" port="9999"/>
<node host="machine2" port="9999"/>
<node host="machine3" port="9999"/>
</sahid>
<antcall target="failsahi"/>
</target>
Attributes and their description
suite | Relative path to the suite file. It is relative to sahi/userdata folder. |
browserType | The browser on which the suite file plays back |
baseurl | Specifies URL which is the starting URL for all the scripts in the suite |
sahihost | Hostname of the server where Sahi is running (Can be IP as well) |
sahiport | Port on which Sahi is running |
failureproperty | The property that gets set to false in case the build fails |
haltonfailure | Takes "true" or "false". Specifies if build should stop executing other tests if one test fails. |
sendemail | Takes "true" or "false". If "true", Sahi sends an email summarizing the playback. |
emailtrigger | Takes "success" or "failure" or "success,failure". Triggers email in case of SUCCESS, FAILURE and both cases respectively. |
emailproperties | Relative path to the properties file that contains details about the mail viz. information about the sender, receiver, host, port, subject, content etc. Path is resolved relative to where this ant target is run from. |
emailPasswordHidden | Takes "true" or "false".If true, it hides the password entered from Sahi console and logs. |
sendemail | Takes "true" or "false". If "true", Sahi sends an email summarizing the playback. |
tags | Optional. Used only for dd.csv and .csv suites. Tags are specified so that it is easy to choose which scripts/testcases to run. eg. in the target above, all the scripts which have 'medium' tag and 'admin' or 'user' (or both) tag will be run. |
originalSuitePath | During drun, suites and scripts are copied to another folder and excecuted. originalSuitePath helps Sahi decide where to generate the failed scripts suite. |
Command to execute the above ANT target
ant -f demo.xml drun
Email.properties file explained
Configuration file for javax.mail
If a value for an item is not provided, then system defaults will be used.mail.smtp.starttls.enable | boolean | If true, enables the use of the STARTTLS command (if supported by the server) to switch the connection to a TLS-protected connection before issuing any login commands. Note that an appropriate trust store must configured so that the client will trust the server's certificate. |
mail.host | String | The server to connect to. |
mail.port | int | The server port to connect to. |
mail.user | String | Default user name. |
mail.password | String | Password |
mail.smtp.auth | boolean | If true, attempt to authenticate the user using the AUTH command. |
mail.isSSL | boolean | If true, uses SSL to connect and use the SSL port by default. |
mail.from | String | Email address of the sender |
mail.to | String | Email address of the sender's To field. For multiple address separate by comma(,). |
mail.cc | String | Email address of the sender's CC field, for multiple address separate by comma(,). |
mail.bcc | String | Email address of the sender's BCC field. for multiple address separate by comma(,). |
mail.subject.prefix | String | The subject for the email. |
mail.content.prefix | String | The body content for the email. |
Sample properties file
mail.smtp.starttls.enable=true
mail.host=smtp.gmail.com
mail.port=25
mail.user=your_email@gmail.com
mail.password=your_password
mail.smtp.auth=true
mail.isSSL=true
mail.from=your_email@gmail.com
mail.to=recepient1@gmail.com,recepient2@gmail.com,recepient3@gmail.com
mail.cc=recepient4@gmail.com,recepient5@gmail.com
mail.bcc=recepient6@gmail.com,recepient7@gmail.com
mail.subject.prefix=my subject
mail.content.prefix=my body