Playback via Ant

abstract This section describes playing back Sahi Flowcharts via Apache Ant.

Playback on a single machine

One can now use the Run Settings dialog to generate the ANT xml automatically. Refer Run Settings 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, check the Add Retry Target checkbox on the Ant Target dialog.

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>.

Command to execute the ANT target file:
ant -f demo.xml
info
  • Taskdef classpath is relative to where ant is run from.
  • The main target is the default target, so you do not need to specify the target when running the xml.
info If you choose the Run sequentially in single browser session option, single session attribute would be set to true. Everything else remains the same.

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 on multiple machines. For more details please refer Jenkins Integration

The machine which distributes the scripts and manages the distributed run is reffered 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

In the Run Settings dialog,

Distributed run on a different Master

In the Run Settings dialog, Refer Distributed Playback for details

info Depending on the scope of run, the fcProjectId, fcFlowchartId and fcPathId properties appear differently in the .xml code.
  • Project level Run: This occurs when the Run button on the Project page is used. All the flowcharts and all the paths within the specified project will be executed. Only fcProjectId property will be present in .xml code.
  • Flowchart level Run: This occurs when the Run button on the Flowchart page is used. Only the specified flowchart among all the flowcharts of the selected project will be executed. Both fcProjectId and fcFlowchartId properties will be present in .xml code.
  • Path level Run: This occurs when the Run button on the Automate dialog is used. Only the specified path among all the paths of the selected flowchart will be executed. All three properties, fcProjectId, fcFlowchartId and fcPathId will be present in .xml code.

Sample ANT xml

The above UIs for Parallel run/distributed run/different master 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="flowcharts" default="drundiffmasterchrome">
    <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:/SahiPro/userdata/scripts/"/>
		<property name="masterhost" value="192.168.1.30"/>
		<property name="masterport" value="9999"/>
	</target>


	<target name="set_properties_chrome" depends="set_properties_common">
		<property name="fcProjectId" value="1. Open Cart Basic"/>
		<property name="fcFlowchartId" value="Shopping Cart"/>
		<property name="fcPathId" value="0"/>
		<property name="fcIsNormalRun" value="true"/>
		<property name="fcIsNegativeValidationRun" value="false"/>
		<property name="fcIsPositiveValidationRun" value="false"/>
		<property name="fcRetryFailuresEnabled" value="false"/>
		<property name="browser" value="chrome"/>
		<property name="startWith" value="BROWSER"/>
		<property name="sendemail" value="true"/>
		<property name="emailtrigger" value="success,failure,user_aborted,aborted_timeout"/>
		<property name="emailattachment" value="success,failure,user_aborted,aborted_timeout"/>
		<property name="emailproperties" value="D:\SahiPro\userdata\config\email.properties"/>
		<property name="sendemailForSubSuite" value="false"/>
		<property name="sendemailperiodically" value="true"/>
		<property name="sendemailperiodicallytime" value="undefined"/>
		<property name="emailPasswordHidden" value="true"/>
		<property name="baseURL" value="http://demoapps.testflowchart.com/opencart/"/>
		<property name="failedSuiteName" value="Shopping Cart_failed_${browser}.flowcharts.dd.csv"/>
		<property name="failedSuite" value="/${failedSuiteName}"/>
		<property name="threads" value="5"/>
		<property name="abortedRetryCount" value="0"/>
		<property name="failureRetryCount" value="0"/>
		<property name="isAvoidSkipping" value="false"/>
		<property name="isSyncConfig" value="false"/>
		<property name="isAutohealEnabled" value="false"/>
		<property name="autoThread" value="false"/>
		<property name="showPeriodicSummary" value="true"/>
		<property name="jsCodeCoverage" value="false"/>
		<property name="configPath" value=""/>
		<property name="suiteTimeOut" value="0.0"/>
		<property name="fcProjectScriptDir" value="$fcProjectScriptDir"/>
	</target>

    <target name="drundiffmasterchrome" depends="set_properties_chrome, set_timestamp">
    	<sahid
			fcProjectId="${fcProjectId}"
			fcFlowchartId="${fcFlowchartId}"
			fcIsNormalRun="${fcIsNormalRun}"
			fcIsNegativeValidationRun="${fcIsNegativeValidationRun}"
			fcIsPositiveValidationRun="${fcIsPositiveValidationRun}"
			fcRetryFailuresEnabled="${fcRetryFailuresEnabled}"
			sendemail="${sendemail}"
			emailtrigger="${emailtrigger}"
			emailattachment="${emailattachment}"
			emailProperties="${emailproperties}"
			sendEmailForSubSuite="${sendemailForSubSuite}"
			sendEmailPeriodically="${sendemailperiodically}"
			sendEmailPeriodicallyTime="${sendemailperiodicallytime}"
			emailPasswordHidden="${emailPasswordHidden}"
			baseurl="${baseURL}"
			sahihost="${masterhost}"
			sahiport="${masterport}"
			failureproperty="sahi.failed.${browser}"
			failedSuiteName="${failedSuiteName}"
			haltonfailure="false"
			browsertype="${browser}"
			startWith="${startWith}"
			scriptsPathMaster="temp/scripts/staging/${ts}_${browser}/"
			scriptsPathInitiator="${scriptDir}"
			threads="${threads}"
			abortedRetryCount="${abortedRetryCount}"
			failureRetryCount="${failureRetryCount}"
			isAvoidSkipping="${isAvoidSkipping}"
			isAutohealEnabled="${isAutohealEnabled}"
			autoThread="${autoThread}"
			isSyncConfig="${isSyncConfig}"
			jsCodeCoverage="${jsCodeCoverage}"
			showPeriodicSummary="${showPeriodicSummary}"
			suiteTimeOut="${suiteTimeOut}"
			isDifferentMaster="true"
			fcProjectScriptDir="${fcProjectScriptDir}"
			ignorePattern=".*(svn|copied).*"
			tags="(user||admin)&&medium"
			userDefinedId="IETestRun1">
			<customfield key="extraParameters" value="filePath"/>
			<!-- 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" 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}" isSyncConfig="${isSyncConfig}" isAutohealEnabled="${isAutohealEnabled}" scriptDir="${scriptDir}">
    	</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="failsahichrome"/>
    </target>

    <target name="failsahichrome" depends="set_properties_chrome" if="sahi.failed.${browser}">
        <fail message="Flowcharts tests failed on browser ${browser}!"/>
    </target>

</project>


danger NOTE: The above XML content is for illustration purposes only. Use the Run Settings dialog to generate the ANT xml content and create an xml with that content.

Attributes

Description of the Attributes in .xml files:

scriptDirSpecifies the path to the scripts folder. Can be the absolute path or a path relative to the userdata folder
fcProjectIdThis contains the name of the project intended to run.
fcFlowchartIdThis contains the name of the particular flowchart we intended to run.
fcPathIdThis contains specific path ID which we intend to run.
fcIsNormalRunThis contains state of the checkbox "Run Normal Path". If checked, the path will run without any validation i.e; with default or data generator's values.
fcIsNegativeValidationRunThis contains state of the checkbox "Run Negative Validations". If checked, the path will run with negative validation values.
fcIsPositiveValidationRunThis contains state of the checkbox "Run Positive Validations". If checked, the path will run with positive validation values.
fcIsRetryFailuresEnabledThis contains state of the checkbox "Add Retry Target". The value needs to be"true" if the user needs to retry the failed path during first run attempt.
If the checkbox for this property is checked, it adds an extra block of xml code. Ex: <target name="retryfailedchrome" depends="set_properties_chrome" if="sahi.failed.${browser}">...</target>]
browserThe browser on which the file plays back
baseUrlSpecifies the starting URL for all the scripts.
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 execution 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.
reportSahi can set offline logs to be generated in xml, html, junit, tm6 and excel types. The default type is html. Check the options required. This is an optional attribute.
fcProjectScriptDirThis contains the project directory. It is internally defined and user need not make any changes to it.
customfieldThis contains the values present in External Variables field. This is an optional attribute.

User can define multiple key-value pairs in the text-box provided(one pair each line). User then needs to copy the content of this text-box to a .propertiesfile and save it with a proper name. Now, the user needs to copy the path of this file into the value section of the .xml file's customfield property.
isAutohealEnabledTakes "true" or "false". If "true", allows scripts to pick element using Sahi auto intelligence when element provided in script is not found. Refer Autoheal section for more details.
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. This is an optional attribute.
masterhostHostname of the different Master server where Sahi is running (Can be IP as well)
masterportPort on which Sahi is running
IsSyncConfigShows status of Sync Configuration checkbox. If checked, it will sync the connfigurations from master machine to other nodes/slave machines.
ConfigPathPort on which Sahi is running

Killing an Ongoing Execution

warning WARNING: Killing single or all ongoing executions in the middle of it is not a routine task. You would kill an execution only if something went wrong and you wish to stop the execution.
Stop All from the Run button's dropdownn menu from the UI can be used to kill all ongoing executions.

This is now possible through an ANT target as well.

The ANT target gives the ability to kill a specific execution or all ongoing executions.

Copy the following content to an empty file and save the file as an xml, say killall.xml in your <SAHI_INSTALLATION_FOLDER>.

<?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"/>

	<target name="kill">
		<sahikill
			sahihost="localhost"
			sahiport="9999">
		</sahikill>
    </target>
</project>


You can now run the default ANT target in the xml file as
ant -f killall.xml
info Alternatively, the following URL can be used to kill all the running scripts:
http://<master machine IP>:9999/_s_/dyn/pro/Master_killAll