| Share
  1. Explore
    Introduction, screen-shots, features, limitations
  2. Getting started
    Prerequisites, download, install, browser configuration, record, playback, view logs
  3. Sahi Scripting Basics - I
    Statements, variables, functions, conditions and looping, _include
  4. Sahi Scripting Basics - II
  5. Sahi APIs (built-in functions)
    1. Browser Accessor APIs
    2. Browser Action APIs
    3. Miscellaneous APIs
  6. Sahi Scripting - Calling Java
  7. Exception handling using try-catch
  8. Recovering without try-catch using _setRecovery
  9. Data Driven Testing
    _getDB, CSV Files, Excel, Databases
  10. Multithreaded Playback (Parallel execution)
    suites, commandline, ant
  11. Advanced techniques, tips and examples
    1. HTTPS/SSL Sites
    2. Configuring an External proxy
    3. Adding jars to Sahi's classpath
  12. Other language drivers Driving Sahi from Java, Ruby etc.
    1. Java
    2. Ruby

Running multiple tests in batch mode ·

Once a few scripts have been recorded, scripted and refactored, they need to be run in a batch mode. Sahi does this via suites.

A suite file is a normal text file with an extension of .suite. For example you may have myapp.suite.

Each line of myapp.suite will have this syntax:
<testName.sah> <absolute url or url relative to the baseurl>

eg.
test1.sah /startPageForTest1.jsp test2.sah http://www.d2.com/startPageForTest2.htm test3.sah abc/startPageForTest3.htm

In the above example, note that the first and third lines use relative urls and the second line uses an absolute url.

The suite can be executed through the command line or through ant.

Using the commandline

The java class net.sf.sahi.test.TestRunner is used to run suites and single tests from the command line.

Usage:
java -cp /path/to/ant-sahi.jar net.sf.sahi.test.TestRunner <test_or_suite_name> <browser_executable> <start_url> <log_dir> <sahi_host> <sahi_port> <number_of_threads> <browser_process_name> [<browser_option>]
Set log_dir to “default” if you want to log to the default log dir.
browser_process_name is used to find and kill browser process. On windows set it to the exe; eg. firefox.exe or iexplore.exe; Note that this attribute was added in Sahi V2 and may not be needed for older Sahi versions.

NOTE: The Sahi proxy needs to be running for TestRunner to work.

Look below in the examples for browser options for various browsers.

————————————

To toggle the proxy for IE, use
..\tools\toggle_IE_proxy.exe enable/disable

You could create a batch or shell script with these commands.

NOTE: indentation in the examples below is for formatting purposes. Remove the indentation and join all of them onto one single line.

eg.

For Internet Explorer 6 and 7, copy the code below to say runsahi.bat:
..\tools\toggle_IE_proxy.exe enable java -cp ..\lib\ant-sahi.jar net.sf.sahi.test.TestRunner D:/sahi/scripts/demo/demo.suite "C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://machine_name:10000/demo/ default localhost 9999 3 iexplore.exe ..\tools\toggle_IE_proxy.exe disable

For Internet Explorer 8:

Internet Explorer 8 needs an additional browser option “-noframemerging” to keep sessions separate.

..\tools\toggle_IE_proxy.exe enable java -cp ..\lib\ant-sahi.jar net.sf.sahi.test.TestRunner D:/sahi/scripts/demo/demo.suite "C:\Program Files\Internet Explorer\IEXPLORE.EXE" http://machine_name:10000/demo/ default localhost 9999 3 iexplore.exe "-noframemerging" ..\tools\toggle_IE_proxy.exe disable

For Firefox:
java -cp ..\lib\ant-sahi.jar net.sf.sahi.test.TestRunner D:/sahi/scripts/demo/demo.suite "C:\Program Files\Mozilla Firefox\firefox.exe" http://machine_name:10000/demo/ default localhost 9999 3 firefox.exe "-profile D:\sahi\browser\ff\profiles\sahi$threadNo -no-remote"

NOTE: sahi$threadNo should be replaced with sahi\$threadNo on linux.

For Chrome:
java -cp ..\lib\ant-sahi.jar net.sf.sahi.test.TestRunner D:/sahi/scripts/demo/demo.suite "C:\\Documents and Settings\\Narayan Raman\\Local Settings\\ Application Data\\Google\\Chrome\\Application\\chrome.exe" http://machine_name:10000/demo/ default localhost 9999 3 chrome.exe "--user-data-dir=$userDir\browser\chrome\profiles\sahi$threadNo --proxy-server=localhost:9999 --disable-popup-blocking"

For Safari:
..\tools\toggle_IE_proxy.exe enable java -cp ..\lib\ant-sahi.jar net.sf.sahi.test.TestRunner D:/sahi/scripts/demo/demo.suite "C:\\Program Files\\Safari\Safari.exe" http://machine_name:10000/demo/ default localhost 9999 1 Safari.exe ..\tools\toggle_IE_proxy.exe disable

For Opera:

Before running from Opera, opera needs to be configured slightly so that crash-recovery and splash screens are disabled.
On Opera, type opera:config in the url bar to edit configuration.
Modify the configuration:
set Recovery Strategy = 0
and
Uncheck Show Problem Dialog

..\tools\toggle_IE_proxy.exe enable java -cp ..\lib\ant-sahi.jar net.sf.sahi.test.TestRunner D:/sahi/scripts/demo/demo.suite "C:\\Program Files\\Opera\\opera.exe" http://machine_name:10000/demo/ default localhost 9999 1 opera.exe ..\tools\toggle_IE_proxy.exe disable

Using ant

Ant target for Internet Explorer 6 and 7:
<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/> <target name="runietests"> <antcall target="proxyon"/> <sahi suite="../scripts/demo/demo.suite" browser="C:\\Program Files\\Internet Explorer\\iexplore.exe" baseurl="http://machine_name/path/" sahihost="localhost" sahiport="9999" failureproperty="sahi.failed" haltonfailure="false" threads="3" browserprocessname="iexplore.exe" > </sahi> <antcall target="proxyoff"/> <antcall target="failsahi"/> </target>

Ant target for Internet Explorer 8:

Internet Explorer 8 needs an additional browser option “-noframemerging” to keep sessions separate.

<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/> <target name="runietests"> <antcall target="proxyon"/> <sahi suite="../scripts/demo/demo.suite" browser="C:\\Program Files\\Internet Explorer\\iexplore.exe" baseurl="http://machine_name/path/" sahihost="localhost" sahiport="9999" failureproperty="sahi.failed" haltonfailure="false" browseroption="-noframemerging" threads="3" browserprocessname="iexplore.exe" > </sahi> <antcall target="proxyoff"/> <antcall target="failsahi"/> </target>

Ant target for firefox:
<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/> <target name="runfftests"> <sahi suite="../scripts/demo/demo.suite" browser="C:\Program Files\Mozilla Firefox\firefox.exe" baseurl="http://machine_name/path/" sahihost="localhost" sahiport="9999" failureproperty="sahi.failed" haltonfailure="false" browseroption="-profile ${basedir}/browser/ff/profiles/sahi$threadNo -no-remote" browserprocessname="firefox.exe" threads="3" > </sahi> <antcall target="failsahi"/> </target>

Ant target for Chrome

<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/> <target name="runchrometests"> <sahi suite="../scripts/demo/demo.suite" browser="C:\\Documents and Settings\\Narayan Raman\\ Local Settings\\Application Data\\Google\\Chrome\\Application\\chrome.exe" baseurl="http://machine_name/path/" sahihost="localhost" sahiport="9999" failureproperty="sahi.failed" haltonfailure="false" browserProcessName="chrome.exe" browseroption="--user-data-dir=$userDir\browser\chrome\profiles\sahi$threadNo --proxy-server=loccalhost:9999 --disable-popup-blocking" threads="3" > </sahi> <antcall target="failsahi"/> </target>

Ant target for Safari
You can only run Safari in one thread if you want it to be killed properly. Also make sure no other Safari instances are running before you invoke this. Other wise new pages will open in tabs.
<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/> <target name="runsafaritests"> <antcall target="proxyon"/> <sahi suite="../scripts/demo/demo.suite" browser="C:\\Program Files\\Safari\Safari.exe" baseurl="http://machine_name/path/" sahihost="localhost" sahiport="9999" failureproperty="sahi.failed" haltonfailure="false" browserProcessName="Safari.exe" threads="1" > </sahi> <antcall target="proxyoff"/> <antcall target="failsahi"/> </target>

Ant target for Opera
You can only run Opera in one thread if you want it to be killed properly. Also make sure no other Opera instances are running before you invoke this. Other wise new pages will open in tabs.

Before running from Opera, opera needs to be configured slightly so that crash-recovery and splash screens are disabled.
On Opera, type opera:config in the url bar to edit configuration.
Modify the configuration:
set Recovery Strategy = 0
and
Uncheck Show Problem Dialog

<taskdef name="sahi" classname="net.sf.sahi.ant.RunSahiTask" classpath="lib/ant-sahi.jar"/> <target name="runsafaritests"> <antcall target="proxyon"/> <sahi suite="../scripts/demo/demo.suite" browser="C:\\Program Files\\Opera\\opera.exe" baseurl="http://machine_name/path/" sahihost="localhost" sahiport="9999" failureproperty="sahi.failed" haltonfailure="false" browserProcessName="opera.exe" threads="1" > </sahi> <antcall target="proxyoff"/> <antcall target="failsahi"/> </target>

The above mentioned proxyon, proxyoff and failsahi targets are defined below:
<target name="proxyon"> <exec executable="tools/toggle_IE_proxy.exe"> <arg value="enable"/> </exec> </target> <target name="proxyoff"> <exec executable="tools/toggle_IE_proxy.exe"> <arg value="disable"/> </exec> </target> <target name="failsahi" if="sahi.failed"> <fail message="Sahi tests failed!"/> </target>

There are example files provided in sahi/batch_runners directory for ant, commandline and ruby. (They are slightly out-dated)




---