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 Editor

The enhanced Editor (available from v6.0.0) allows the user to playback scripts, suites, data driven suites and scenarios from a web interface. Scripts/Suites can be playbacked on a single machine or distribute across machines. One can also generate ANT xml content for various scenarios from the Playback UI.

Please refer to the Playback section of the Editor documentation for more details on the Playback UI.

Playback via ANT

Playback on a single machine

One can now use the Editor Playback UI to generate the ANT xml automatically. Refer here for details on the UI. This will generate the contents of an ANT xml file. If you wish to add a Retry target as well, click on the Show Retry Target button on the next window.

Once the ANT xml content is generated, copy the content to an empty file and save the file as an xml, say demo.xml in your <SAHI_INSTALLATION_FOLDER>. You can now run the default ANT target in the xml file as
ant -f demo.xml


NOTE: The main target is the default target, so you do not need to specify the target when running the xml.

The above UI would generate an ANT xml that looks like the following.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/**
 * Copyright Tyto Software Pvt. Ltd.
 */
-->
<project name="demo" default="runtestsie">
	<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask"  classpath="lib/ant-sahi.jar"/>

	<target name="set_timestamp">
        <tstamp>
            <format property="ts" pattern="yyyy_MM_dd__HH_mm_ss" locale="en, IN"/>
        </tstamp>
	</target>


	<target name="set_properties_ie" depends="set_timestamp">
    		<property name="scriptDir" value="D:/sahi/userdata/scripts/"/>
    		<property name="scriptName" value="demo/ddcsv/test.dd.csv"/>
		<property name="browser" value="ie"/>
		<property name="sendemail" value="true"/>
		<property name="emailtrigger" value="success,failure"/>
		<property name="emailproperties" value="D:\sahi\userdata\config\email.properties"/>
		<property name="sendemailperiodically" value="true"/>
		<property name="sendemailperiodicallytime" value="30"/>
		<property name="emailPasswordHidden" value="true"/>
		<property name="baseURL" value="http://sahitest.com/demo/"/>
		<property name="host" value="localhost"/>
		<property name="port" value="9999"/>
		<property name="singlesession" value="false"/>
		<property name="showPeriodicSummary" value="true"/>
		<property name="threads" value="5"/>
		<property name="failedSuiteName" value="test_failed_${browser}.dd.csv"/>
		<property name="failedSuite" value="demo/ddcsv/${failedSuiteName}"/>
	</target>

	<target name="runtestsie" depends="set_properties_ie">
		<sahi suite="${scriptName}"
			browsertype="${browser}"
			sendemail="${sendemail}"
	        	emailtrigger="${emailtrigger}"
	        	emailproperties="${emailproperties}"
	       		sendEmailPeriodically="${sendemailperiodically}"
			sendEmailPeriodicallyTime="${sendemailperiodicallytime}"
			emailPasswordHidden="${emailPasswordHidden}"
			baseurl="${baseURL}"
			sahihost="${host}"
			sahiport="${port}"
			scriptsPathMaster="${scriptDir}"
			failureproperty="sahi.failed.${browser}"
			failedSuiteName="${failedSuiteName}"
			haltonfailure="false"
			singlesession="${singlesession}"
			threads="${threads}"
			showPeriodicSummary="${showPeriodicSummary}"
			tags="(user||admin)&&medium"
			userDefinedId="IETestRun1">
			
			<!-- Custom fields - add, edit or remove as required -->
			<customfield key="user" value="test"/>
			<customfield key="mask_password" value="secret"/>
			<!-- Offline reports -->
			<report type="xml"/>
			<report type="html" logdir="d:/temp/html"/>
			
		</sahi>
		<antcall target="failsahiie"/>
	</target>

    <target name="failsahiie" depends="set_properties_ie" if="sahi.failed.${browser}">
        <fail message="Sahi tests failed on browser ${browser}!"/>
    </target>
</project>


info If you choose the Run sequentially in single browser session option, singlesession attribute would be set to true. Everything else remains the same.
danger Please NOTE: The above XML content is for illustration purposes only. Use the Editor UI to generate the ANT xml content and create an xml with that content in your <SAHI_INSTALLATION_FOLDER>.
Let us look at the important attributes used in the ANT xml target (specified in bold above).

Attributes and their description

info taskdef classpath is relative to where ant is run from.
scriptDirSpecifies the path to the scripts folder. Can be the absolute path or a path relative to the userdata folder
scriptNameRelative path to the script/suite/data driven suite. It is relative to scriptDir.
browserThe browser on which the suite file plays back
baseurlSpecifies URL which is the starting URL for all the scripts in the suite
hostHostname of the server where Sahi is running (Can be IP as well)
portPort on which Sahi is running
threadsNumber of simultaneous browser instances on which sahi tests will be run.
singlesessionSince this is a parallel run, it will be "false". If "true", runs all scripts in a single browser without closing it between scripts.
showPeriodicSummaryTakes "true" or "false". If "true", a periodic summary of script status is logged in the Ant Console.
sendemailTakes "true" or "false". If "true", Sahi sends an email summarizing the playback.
emailtriggerTakes "success" or "failure" or "success,failure". Triggers email in case of SUCCESS, FAILURE and both cases respectively.
emailpropertiesPath to the properties file that contains details about the mail viz. information about the sender, receiver, host, port, subject, content etc. Path can be the absolute path or relative to where this ant target is run from.
sendemailperiodicallyTakes "true" or "false". If "true", Sahi will send emails periodically till the suite run is complete.
sendemailperiodicallytimeSpecifies the interval in minutes at which periodic emails are to be sent.
failedSuiteNameName of the failed suite. It is of the form <suitename>_failed_<browser>.suite.
failedsuiteRelative path to the failed suite. It is relative to scriptDir.
tagsTags should be specified 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.
userdefinedidThe unique id that the user can pass to differentiate a suite from others. This is an optional attribute.
customfieldCustom fields can be passed to the scripts using the customfield attribute. More than one custom field can be passed, by specifying additional customfield entries. Replace the custom field keys and values as appropriate. This is an optional attribute.
reportSahi can set offline logs to be generated in xml, html, junit, tm6 and excel types. The default type is html. Add separate entries for each report type as required. This is an optional attribute.

Command to execute the above ANT target

ant -f demo.xml


Distributed playback via ANT

Distributed playback can be achieved through ANT targets as well.

These targets can be used from Jenkins to distribute the scripts of a suite on multiple machines.

The machine which distributes the scripts and manages the distributed run is referred to as the Master. All logs are visible from the Master. The other machines are called Slaves. Any machine in the distributed environment can serve as the Master. The machine which launches the distributed run is referred to as the Initiator.

Distributed run on the same Master

Use the Editor Playback UI to generate the ANT xml content.

In the Editor Playback UI, This will generate the contents of an ANT xml file. If you wish to add a Retry target as well, click on the Show Retry Target button on the next window.

Once the ANT xml content is generated, copy the content to an empty file and save the file as an xml, say demo.xml in your <SAHI_INSTALLATION_FOLDER>. You can now run the default ANT target in the xml file as
ant -f demo.xml


NOTE: The main target is the default target, so you do not need to specify the target when running the xml.

The above UI would generate an ANT xml that looks like the following.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/**
 * Copyright Tyto Software Pvt. Ltd.
 */
-->
<project name="demo" default="drunie">
    <taskdef name="sahid" classname="in.co.sahi.ant.DAntRunner" classpath="lib/ant-sahi.jar"/>

	<target name="set_timestamp">
        <tstamp>
            <format property="ts" pattern="yyyy_MM_dd_HH_mm_ss" locale="en, IN"/>
        </tstamp>
	</target>

	<target name="set_properties_common" depends="set_timestamp">
    		<property name="scriptDir" value="D:/sahi/userdata/scripts/"/>
		<property name="host" value="localhost"/>
		<property name="port" value="9999"/>
	</target>



	<target name="set_properties_ie" depends="set_properties_common">
    		<property name="scriptName" value="demo/ddcsv/test.dd.csv"/>
		<property name="browser" value="ie"/>
		<property name="sendemail" value="true"/>
		<property name="emailtrigger" value="success,failure"/>
		<property name="emailproperties" value="D:\sahi\userdata\config\email.properties"/>
		<property name="sendemailperiodically" value="true"/>
		<property name="sendemailperiodicallytime" value="30"/>
		<property name="emailPasswordHidden" value="true"/>
		<property name="baseURL" value="http://sahitest.com/demo/"/>
		<property name="showPeriodicSummary" value="true"/>
		<property name="failedSuiteName" value="test_failed_${browser}.dd.csv"/>
		<property name="failedSuite" value="demo/ddcsv/${failedSuiteName}"/>
		<property name="threads" value="5"/>
	</target>

    <target name="drunie" depends="set_properties_ie, set_timestamp">
    	<sahid suite="${scriptName}"
			sendEmail="${sendemail}"
			emailtrigger="${emailtrigger}"
			emailProperties="${emailproperties}"
			sendEmailPeriodically="${sendemailperiodically}"
			sendEmailPeriodicallyTime="${sendemailperiodicallytime}"
			emailPasswordHidden="${emailPasswordHidden}"
			baseurl="${baseURL}"
			sahihost="${host}"
			sahiport="${port}"
			failureproperty="sahi.failed.${browser}"
			failedSuiteName="${failedSuiteName}"
			haltonfailure="false"
			browsertype="${browser}"
			scriptsPathMaster="${scriptDir}"
			threads="${threads}"
			showPeriodicSummary="${showPeriodicSummary}"
			ignorePattern=".*(svn|copied).*"
			tags="(user||admin)&&medium"
			userDefinedId="IETestRun1">
			
			<!-- Custom fields - add, edit or remove as required -->
			<customfield key="user" value="test"/>
			<customfield key="mask_password" value="secret"/>
			<!-- Scripts will be distributed across all the nodes. The nodes may or may not include the Master machine -->
			<node host="localhost" port="9999"/>
			<node host="192.168.1.29" port="9999"/>
			<!-- Offline reports -->
			<report type="xml"/>
			<report type="html" logdir="d:/temp/html"/>
			
    	</sahid>
	<antcall target="failsahiie"/>
    </target>

    <target name="failsahiie" depends="set_properties_ie" if="sahi.failed.${browser}">
        <fail message="Sahi tests failed on browser ${browser}!"/>
    </target>
</project>


danger Please NOTE: The above XML content is for illustration purposes only. Use the Editor UI to generate the ANT xml content and create an xml with that content in your <SAHI_INSTALLATION_FOLDER>.
Let us look at the important attributes used in the ANT xml target (specified in bold above).

Attributes and their description

info taskdef classpath is relative to where ant is run from.
scriptDirSpecifies the path to the scripts folder. Can be the absolute path or a path relative to the userdata folder
hostHostname of the server where Sahi is running (Can be IP as well). Leave this as localhost
portPort on which Sahi is running
scriptNameRelative path to the script/suite/data driven suite. It is relative to scriptDir.
browserThe browser on which the suite file plays back
threadsNumber of simultaneous browser instances on which sahi tests will be run.
showPeriodicSummaryTakes "true" or "false". If "true", a periodic summary of script status is logged in the Ant Console.
baseurlSpecifies URL which is the starting URL for all the scripts in the suite
sendemailTakes "true" or "false". If "true", Sahi sends an email summarizing the playback.
emailtriggerTakes "success" or "failure" or "success,failure". Triggers email in case of SUCCESS, FAILURE and both cases respectively.
emailpropertiesPath to the properties file that contains details about the mail viz. information about the sender, receiver, host, port, subject, content etc. Path can be the absolute path or relative to where this ant target is run from.
sendemailperiodicallyTakes "true" or "false". If "true", Sahi will send emails periodically till the suite run is complete.
sendemailperiodicallytimeSpecifies the interval in minutes at which periodic emails are to be sent.
failedSuiteNameName of the failed suite. It is of the form <suitename>_failed_<browser>.suite.
failedsuiteRelative path to the failed suite. It is relative to scriptDir.
tagsTags should be specified 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.
userdefinedidThe unique id that the user can pass to differentiate a suite from others. This is an optional attribute.
nodeEach node attribute specifies a machine on which the tests should run. Add as many node entries as there are machines to run. The nodes may or may not include the Master machine (localhost). If the Master machine is not included, scripts will not be run on the Master. There can be 1 or more nodes.
customfieldCustom fields can be passed to the scripts using the customfield attribute. More than one custom field can be passed, by specifying additional customfield entries. Replace the custom field keys and values as appropriate. This is an optional attribute.
reportSahi can set offline logs to be generated in xml, html, junit, tm6 and excel types. The default type is html. Add separate entries for each report type as required. This is an optional attribute.

Command to execute the above ANT target

ant -f demo.xml


Distributed run on a different Master

Use the Editor Playback UI to generate the ANT xml content.

In the Editor Playback UI, This will generate the contents of an ANT xml file. If you wish to add a Retry target as well, click on the Show Retry Target button on the next window.

Once the ANT xml content is generated, copy the content to an empty file and save the file as an xml, say demo.xml in your <SAHI_INSTALLATION_FOLDER>. You can now run the default ANT target in the xml file as
ant -f demo.xml


NOTE: The main target is the default target, so you do not need to specify the target when running the xml.

The above UI would generate an ANT xml that looks like the following.
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/**
 * Copyright Tyto Software Pvt. Ltd.
 */
-->
<project name="demo" default="drundiffmasterie">
    <taskdef name="sahid" classname="in.co.sahi.ant.DAntRunner" classpath="lib/ant-sahi.jar"/>
    <taskdef name="sahisync" classname="in.co.sahi.ant.DAntSync" classpath="lib/ant-sahi.jar"/>
	<taskdef name="sahipull" classname="in.co.sahi.ant.DAntPull" classpath="lib/ant-sahi.jar"/>
	<taskdef name="sahidelete" classname="in.co.sahi.ant.DAntDelete" classpath="lib/ant-sahi.jar"/>

	<target name="set_timestamp">
        	<tstamp>
            	<format property="ts" pattern="yyyy_MM_dd__HH_mm_ss" locale="en, IN"/>
        	</tstamp>
	</target>

	<target name="set_properties_common" depends="set_timestamp">
    		<property name="scriptDir" value="D:/sahi/userdata/scripts/"/>
		<property name="masterhost" value="192.168.1.30"/>
		<property name="masterport" value="9999"/>
	</target>



	<target name="set_properties_ie" depends="set_properties_common">
		<property name="scriptName" value="demo/ddcsv/test.dd.csv"/>
		<property name="browser" value="ie"/>
		<property name="sendemail" value="true"/>
		<property name="emailtrigger" value="success,failure"/>
		<property name="emailproperties" value="D:\sahi\userdata\config\email.properties"/>
		<property name="sendemailperiodically" value="true"/>
		<property name="sendemailperiodicallytime" value="30"/>
		<property name="emailPasswordHidden" value="true"/>
		<property name="baseURL" value="http://sahitest.com/demo/"/>
		<property name="failedSuiteName" value="test_failed_${browser}.dd.csv"/>
		<property name="failedSuite" value="demo/ddcsv/${failedSuiteName}"/>
		<property name="threads" value="5"/>
		<property name="showPeriodicSummary" value="true"/>
	</target>

    <target name="drundiffmasterie" depends="set_properties_ie, set_timestamp">
    	<!-- Sync suite to Master staging folder -->
		<sahisync originFolder="${scriptDir}" destFolder="temp/scripts/staging/${ts}_${browser}" ignorePattern=".*(svn|copied).*" suitePath="${scriptDir}${scriptName}" csvSeparator="," scriptExtensions="sah;sahi;js" scenarioExtensions=".s.csv;xls;xlsx">
	    	<node host="${masterhost}" port="${masterport}"/>
		</sahisync>

    	<sahid suite="${scriptName}"
			sendEmail="${sendemail}"
			emailtrigger="${emailtrigger}"
			emailProperties="${emailproperties}"
			sendEmailPeriodically="${sendemailperiodically}"
			sendEmailPeriodicallyTime="${sendemailperiodicallytime}"
			emailPasswordHidden="${emailPasswordHidden}"
			baseurl="${baseURL}"
			sahihost="${masterhost}"
			sahiport="${masterport}"
			failureproperty="sahi.failed.${browser}"
			failedSuiteName="${failedSuiteName}"
			haltonfailure="false"
			browsertype="${browser}"
			scriptsPathMaster="temp/scripts/staging/${ts}_${browser}/"
			scriptsPathInitiator="${scriptDir}"
			threads="${threads}"
			showPeriodicSummary="${showPeriodicSummary}"
			isDifferentMaster="true"
			ignorePattern=".*(svn|copied).*"
			tags="(user||admin)&&medium"
			userDefinedId="IETestRun1">
			
			<!-- Custom fields - add, edit or remove as required -->
			<customfield key="user" value="test"/>
			<customfield key="mask_password" value="secret"/>
			<!-- Scripts will be distributed across all the nodes. The nodes may or may not include the Master machine -->
			<node host="192.168.1.28" port="9999"/>
			<node host="192.168.1.29" port="9999"/>
			
			<!-- Offline reports -->
			<report type="xml" logdir="logs/temp/xml/${ts}"/>
			<report type="html" logdir="logs/temp/html/${ts}"/>
    	</sahid>

    	<!-- Delete suite from Master staging folder -->
		<sahidelete host="${masterhost}"
    			port="${masterport}"
    			filePath="temp/scripts/staging/${ts}_${browser}">
    		</sahidelete>
		<!-- Pull the logs from the Master onto the Initiator machine -->
		<sahipull sourceHost="192.168.1.30" sourcePort="9999" originFolder="logs/temp/xml/${ts}" destFolder="logs/xml" ignorePattern=".*(svn|copied).*"/>
		<sahipull sourceHost="192.168.1.30" sourcePort="9999" originFolder="logs/temp/html/${ts}" destFolder="d:/temp/html" ignorePattern=".*(svn|copied).*"/>
		<antcall target="failsahiie"/>
    </target>

    <target name="failsahiie" depends="set_properties_ie" if="sahi.failed.${browser}">
        <fail message="Sahi tests failed on browser ${browser}!"/>
    </target>

</project>


danger Please NOTE: The above XML content is for illustration purposes only. Use the Editor UI to generate the ANT xml content and create an xml with that content.
Let us look at the important attributes used in the ANT xml target (specified in bold above).

Attributes and their description

info taskdef classpath is relative to where ant is run from.
scriptDirSpecifies the path to the scripts folder on the Initiator machine. This can be an absolute path or a path relative to where Ant is run from
masterhostHostname of the different Master server where Sahi is running (Can be IP as well)
masterportPort on which Sahi is running
scriptNameRelative path to the script/suite/data driven suite. It is relative to scriptDir.
browserThe browser on which the suite file plays back
baseurlSpecifies URL which is the starting URL for all the scripts in the suite
threadsNumber of simultaneous browser instances on which sahi tests will be run.
showPeriodicSummaryTakes "true" or "false". If "true", a periodic summary of script status is logged in the Ant Console.
sendemailTakes "true" or "false". If "true", Sahi sends an email summarizing the playback.
emailtriggerTakes "success" or "failure" or "success,failure". Triggers email in case of SUCCESS, FAILURE and both cases respectively.
emailpropertiesPath to the properties file that contains details about the mail viz. information about the sender, receiver, host, port, subject, content etc. Path can be the absolute path or relative to where this ant target is run from.
sendemailperiodicallyTakes "true" or "false". If "true", Sahi will send emails periodically till the suite run is complete.
sendemailperiodicallytimeSpecifies the interval in minutes at which periodic emails are to be sent.
failedSuiteNameName of the failed suite. It is of the form <suitename>_failed_<browser>.suite.
failedsuiteRelative path to the failed suite. It is relative to scriptDir.
tagsTags should be specified 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.
userdefinedidThe unique id that the user can pass to differentiate a suite from others. This is an optional attribute.
nodeEach node attribute specifies a machine on which the tests should run. Add as many node entries as there are machines to run. The nodes may or may not include the Master machine. If the Master machine is not included, scripts will not be run on the Master. There can be 1 or more nodes.
customfieldCustom fields can be passed to the scripts using the customfield attribute. More than one custom field can be passed, by specifying additional customfield entries. Replace the custom field keys and values as appropriate. This is an optional attribute.

Command to execute the above ANT target

ant -f demo.xml


Email.properties file explained

infoFor details about sending emails, please refer Sending Emails.

Configuration file for javax.mail

If a value for an item is not provided, then system defaults will be used.

mail.smtp.starttls.enablebooleanIf 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.hostStringThe server to connect to.
mail.portintThe server port to connect to.
mail.userStringDefault user name.
mail.passwordStringPassword
mail.smtp.authbooleanIf true, attempt to authenticate the user using the AUTH command.
mail.isSSLbooleanIf true, uses SSL to connect and use the SSL port by default.
mail.fromStringEmail address of the sender
mail.toStringEmail address of the sender's To field. For multiple address separate by comma(,).
mail.ccStringEmail address of the sender's CC field, for multiple address separate by comma(,).
mail.bccStringEmail address of the sender's BCC field. for multiple address separate by comma(,).
mail.subject.prefixStringThe subject prefix 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=false
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


Email template

Emails that get sent out at the end of a suite run, use a template. This template can be viewed from email_template.txt in the Configure UI.

The layout, format and content can be modified.

With regard to content, the following information can be added. With regard to subject, it can be provided at the top of email_template.txt like the following:
Subject : $STATUS - $SUITEINFO_SUITENAME - $SUITEINFO_HOST - $SUITEINFO_PORT


If subject is provided in email_template.txt then mail.subject.prefix property will not be prefixed for the mail. If subject is not provided in email_template.txt then default subject will be set in the mail.
warning email_template.xsl has been introduced from Sahi Pro 7.5.0. email_template.txt has been removed from the Configuration.

To provide subject in email_template.xsl, add the below mentioned code at line number 2 in email_template.xsl:
<!-- Subject : $STATUS - $SUITEINFO_SUITENAME - $SUITEINFO_HOST - $SUITEINFO_PORT -->

Distributed Runs - More Information

The following information is applicable for distributed runs on the same Master as well as on a different Master. It is applicable irrespective of how the run was executed - Editor, ANT xml, batch file or shell script, etc.

Smart zip (from SahiPro 6.1.0)

In versions prior to SahiPro 6.1.0, the entire scripts folder would get synced to different nodes. If the scripts folder was huge, this would take time and also cause memory issues at times. As of SahiPro 6.1.0, we only sync the scripts necessary to execute a run. Please refer to _resource API on how to include resources used in your scripts.

Distribute scripts in rotation (from SahiPro 6.1.0)

Prior to SahiPro 6.1.0, if there were multiple nodes, priority would always be given to the first node in the Nodes list, and would decrease as we go to the end of the nodes list. Thus you would always find that more scripts were run on the initial nodes than on the nodes at the end of the list. As of this release, scripts are assigned to nodes one by one so long as capacity is available on the node. So scripts get rotated and the distribution becomes more even across Nodes.

For example, assume that there are 4 nodes, the capacity of Chrome browser on each node is 5, and that there are 50 scripts to distribute. Prior to SahiPro 6.1.0 - The first 5 scripts will go to Node 1. If at the time of assigning the 6th script, any of the earlier 5 scripts gets completed, the 6th script would also go to Node 1 since it has free capacity. As of SahiPro 6.1.0 - The first script will go to Node 1, the second to Node 2, and so on.

Scripts rotation can be switched off by setting the flag drun.run_scripts_in_rotation to false in userdata.properties. By default, this value is true.

Nodes monitoring (from SahiPro 6.1.0)

From SahiPro 6.1.0, the nodes participating in a distributed run are now monitored internally. Node monitoring can be turned off by setting the flag drun.nodes_monitoring_enabled to false in userdata.properties. By default, this value is true.

Ability to register Nodes externally (from SahiPro 6.1.0)

It is now possible to register a new Node for a currently running distributed run.

Using registerNodes.bat/registerNodes.sh
  1. Open a command prompt and cd to sahi/userdata/bin (or click on the "Bin" link on the Sahi Dashboard)
  2. Run register_nodes.bat to see the syntax
    D:\sahi_pro\userdata\bin>register_nodes.bat -- Usage: register_nodes.bat <extnodes> <userDefinedId> <suiteId> - extnodes is a comma separated string of host:port combos, example: "machine1:9999,machine2:9999". If multiple nodes are specified, enclose them in double quotes. - userDefinedId is the User defined Id specified while running the original suite - suiteId is the SuiteId of the running suite, and can be found from Suite Info section in the Suite Report log - NOTE: Only one of suiteId or userDefinedId is required. If both suiteId and userDefinedId are passed, suiteId will be used to identify the running suite. -- Example: 1. Registering one machine using userDefinedId (say abc1234). register_nodes.bat machine1:9999 abc1234 2. Registering more than one machine using userDefinedId. register_nodes.bat "machine1:9999,machine2:9999" abc1234 3. Registering one machine using suiteId (say sahi_a0ba301605a8f04cb10881e0ddcd96f9dfbd). NOTE: Some value HAS to be passed for the second parameter - userDefinedId. Pass "". register_nodes.bat machine1:9999 "" sahi_a0ba301605a8f04cb10881e0ddcd96f9dfbd 4. Registering more than one machine using suiteId. NOTE: Some value HAS to be passed for the second parameter - userDefinedId. Pass "". register_nodes.bat "machine1:9999,machine2:9999" "" sahi_a0ba301605a8f04cb10881e0ddcd96f9dfbd -- D:\sahi_pro\userdata\bin>
  3. Nodes can be registered for a currently running suite. The suite can be specified either using userDefinedId or suiteId. If both are specified, suiteId will be used. suiteId for the current run can be found from the Suite Info section of the Suite report logs.
    • To register using userDefinedId, use something like the following
      register_nodes.bat "192.168.1.100:9999,192.168.1.101:9999" myUserDefinedId
      info Multiple nodes can be specified using comma separator. If more than one node is specified, use double quotes for the nodes.
      Note that these values are indicative. Please use your own values.
    • To register using suiteId, use something like the following
      register_nodes.bat "192.168.1.100:9999,192.168.1.101:9999" "" sahi_a0ba301605a8f04cb10881e0ddcd96f9dfbd
      info
      • Pass "" as the second parameter for userDefinedId.
      • Multiple nodes can be specified using comma separator. If more than one node is specified, use double quotes for the nodes.
      Note that these values are indicative. Please use your own values.
Using an ANT target Copy the following content to an empty file and save the file as an xml, say registernodes.xml in your <SAHI_INSTALLATION_FOLDER>. You can now run the default ANT target in the xml file as
ant -f registernodes.xml


<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/**
 * Copyright Tyto Software Pvt. Ltd.
 */
-->
<project name="demo" default="register">
    <taskdef name="sahinodeclient" classname="in.co.sahi.ant.DAntNodeClient" classpath="lib/ant-sahi.jar"/>

	<!-- Use suiteId or userDefinedId. If both are specified, suiteId would be used. -->
	<target name="register">
		<sahinodeclient
			sahihost="localhost"
			sahiport="9999"
			userDefinedId="myUserDefinedId">
			<node host="192.168.1.100" port="9999"/>
			<node host="192.168.1.101" port="9999"/>
		</sahinodeclient>
	</target>
</project>


Please note all these values are indicative.

Attributes and their description
info taskdef classpath is relative to where ant is run from.
sahihostHostname of the Master where Sahi is running (Can be IP as well).
sahiportPort on which Sahi is running
userDefinedIdUserDefinedId specified while running the original suite
suiteIdSuiteId of the running suite. Get this value from the Suite Info section of the Suite Report logs
nodeSpecify one entry each for every node that you want to register.
info Specify either userDefinedId or suiteId. If both are specified, suiteId will be used.
Command to execute the above ANT target
ant -f registernodes.xml


Killing a running script/suite

warning WARNING: Killing a suite (or all running suites) in the middle of a run is not a routine task. You would kill a suite only if something went wrong and you wish to stop the suite execution.
Stop All from the Editor can be used to kill all running scripts/suites.

This is now possible through an ANT target as well.

The ANT target gives the ability to kill a specific running suite or kill all the running suites.

Copy the following content to an empty file and save the file as an xml, say killall.xml in your <SAHI_INSTALLATION_FOLDER>. You can now run the default ANT target in the xml file as
ant -f killall.xml


<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
/**
 * Copyright Tyto Software Pvt. Ltd.
 */
-->
<project name="demo" default="kill">
    <taskdef name="sahikill" classname="in.co.sahi.ant.DKillTask" classpath="lib/ant-sahi.jar"/>

	<!-- This target will kill the running suite(s) on sahihost. sahihost can be other than localhost as well. -->
	<!-- If neither suiteId nor userDefinedId is specified, all running suites on this Master will be killed. -->
	<!-- If you wish to kill a specific suite, use suiteId or userDefinedId. If both are specified, suiteId would be used. -->
	<target name="kill">
		<sahikill
			sahihost="localhost"
			sahiport="9999">
		</sahikill>
    </target>
</project>


Attributes and their description
info taskdef classpath is relative to where ant is run from.
sahihostHostname of the Master where Sahi is running (Can be IP as well).
sahiportPort on which Sahi is running
userDefinedIdUserDefinedId specified while running the original suite
suiteIdSuiteId of the running suite. Get this value from the Suite Info section of the Suite Report logs
info
  • If neither suiteId nor userDefinedId is specified, all running suites on this Master will be killed.
  • If you wish to kill a specific suite, use suiteId or userDefinedId. If both are specified, suiteId would be used.
Command to execute the above ANT target
ant -f killall.xml


Changes in staging and copied folders behaviour (from Sahi Pro v6.1.0)

In a distributed run, scripts get copied to Nodes in temp/scripts/copied directory, under timestamped folders. At the end of the run, these timestamped folders get deleted. Likewise, in a distributed run on a different Master, scripts first get synced to a timestamped folder inside temp/scripts/staging directory of the Master. At the end of the run, these timestamped folders get deleted.

These changes have been done to support sharing of a Master or Node between different distributed runs at the same time.

If for debugging purposes, one wants the staging and copied folders to remain undeleted, one can set the flag drun.debugging_enabled to true in userdata.properties. Please refer to instructions in sahi.properties. Use with extreme caution. By default, this value is false.

Experimental feature: Ability to share Master and Nodes between different distributed runs (from Sahi Pro v6.1.0)

It is possible now to use a machine as Master for different distributed runs in parallel. The same applies for Nodes as well. This could be useful in a Test Lab kind of environment where a powerful machine can serve as the Master for multiple distributed runs.

Periodic Summary during Script Playback

By default, a periodic summary of the script execution is shown when running the scripts from Script Editor, Ant, Testrunner, Drun and Drun Diff Master. Whenever there is a change in the status of script, it will be printed in the Console or shown as an Editor notification.

A sample periodic summary on Ant, Testrunner, Drun and Drun Diff Master Console will look like the following:

May 30, 2016 04:31:20 PM STARTED: label.sah BROWSER: chrome May 30, 2016 04:31:20 PM STARTED: screenSize.sah BROWSER: chrome May 30, 2016 04:31:25 PM PASSED: screenSize.sah BROWSER: chrome May 30, 2016 04:31:25 PM Testcases: 0/0, Scripts: 1/2 BROWSER: chrome May 30, 2016 04:31:39 PM FAILED: label.sah BROWSER: chrome May 30, 2016 04:31:39 PM Testcases: 0/0, Scripts: 1/2 BROWSER: chrome


There are two kind of messages that come up in the console.
[timestamp] [status: scriptname] [BROWSER: browsername]
[timestamp] [Testcases: passed/total_ran] [Scripts: passed/total_ran] [BROWSER: browsername]
timestampTime Stamp of the Initiator machine.
status: scriptnameStatus of the script (STARTED, PASSED, FAILED) followed by script name.
Testcases: passed / total_ranTotal number of testcases passed / Total number of testcases executed.
Scripts: passed / total_ranTotal number of scripts passed / Total number of scripts executed.
BROWSER: browsernameBrowser on which the script was executed.
When playing back the scripts from the Editor, these messages appear as notifications on the bottom right corner of the Editor. The message will look like as below
info NOTE: The Initiator and the Master machine should be on Sahi Pro v6.3.0 for this to work. We would recommend you to use Sahi Pro v6.3.0 on the slave machines as well.

Playback via MAVEN

Pre-requisites

Maven should be configured in your System Environment Variables, to verify type the following in a terminal or in a command prompt
mvn --version
  1. Create a new Maven project in Eclipse.
    • From the File menu, choose New, and then choose Project.
    • In the New Project window, choose Maven Project.
    • In the New Maven Project window, choose Create a simple project, and leave other default selections.
    • In the New Maven Project, Configure project windows, type the following Artifact information:
      • Group Id: sahi-example
      • Artifact Id: sahi-integration-maven
      • Version: 0.0.1-SNAPSHOT
      • Packaging: jar
      • Name: sahi-integration-maven
    • Click Finish
  2. Add JDK to the project
    • Open the context (right-click) menu for the Maven Project, choose Build Path, and then choose Congifure Build Path.
    • In the Java Build Path windows, select JRE System Library under Libraries.
    • Click Edit then select Alternate JRE and browse JDK path installed in your System.
    • Click Finish
  3. Edit the pom.xml from
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>sahi-examples</groupId>
      <artifactId>sahi-integration-example</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>sahi-integration-example</name>
    
    </project>
    to
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
      <groupId>sahi-examples</groupId>
      <artifactId>sahi-integration-example</artifactId>
      <version>0.0.1-SNAPSHOT</version>
      <name>sahi-integration-example</name>
    
    <build>
         <plugins>
           <plugin>
              <artifactId>maven-antrun-plugin</artifactId>
              <version>1.7</version>
              <executions>
                 <execution>
                 <phase>generate-sources</phase>
                    <configuration>
                       <target name="target_to_be_executed">
                          <ant dir="<SahiInstallationDir>" antfile="build.xml" />
                       </target>
                    </configuration>
                    <goals>
                       <goal>run</goal>
                    </goals>
                 </execution>
              </executions>
           </plugin>
        </plugins>
    </build>
    
    </project>
  4. info Copy only the build tag in the project tag
    infoChange SahiInstallationDir, target name and antfile accroding to your Configuration.
    info To know more about Create ant file
  5. Run : open the context (right-click) menu for the project, choose Run As, and then choose Maven generate-sources, Maven test etc.

TypeScript Playback

Pre-requisites

  1. Node.js must be installed in the system.
  2. TypeScript must be installed in the system.

Building TypeScript

  1. Copy <SahiPro>/userdata/scripts/demo/typescript/sahi_apis.ts file in your TypeScript workspace.
  2. Create tsconfig.json in your workspace, if not exist and put the following contents
    {
        "compileOnSave": true,
        "compilerOptions": {
            "target": "es3",
            "outDir": "<SahiPro>/userdata/scripts/demo/typescript/out"
        }
    }
    infoNOTE: Replace <SahiPro> with the Sahi Pro installation directory. Target should be es3
  3. Open the TypeScript workspace in MS Code and build the project.
    Go to: Tasks -> Run Build Task -> tsc:build
    Or,

    Open a command prompt/bash, cd to TypeScript workspace and run tsc.
  4. It will build the TypeScript workspace and create JavaScript files in <SahiPro>/userdata/scripts/demo/typescript/out directory.
  5. Open the JavaScript files in Sahi Pro Editor and run the script.