Top Rounds
| We are Hiring! |

Running multiple tests in batch mode (V3.5) ·

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> <(optional) absolute url or url relative to the baseurl>

eg.
test1.sah /startPageForTest1.jsp test2.sah http://www.myappdomain.com/startPageForTest2.htm test3.sah //commented_test1.sah #commented_test2.sah test4.sah abc/startPageForTest3.htm

In the above example, note that the first and last 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

testrunner.bat and testrunner.sh

1) Open a command prompt and cd to sahi/userdata/bin
(or click on the “Bin” link on the Sahi Dashboard)
2) Run testrunner.bat to see the syntax
C:\sahi\userdata\bin>testrunner.bat Usage: testrunner.bat <sah file|suite file|folder containing scripts> <startURL> <browserType> File path is relative to userdata/scripts Example: testrunner.bat demo/demo.suite http://sahi.co.in/demo/ firefox testrunner.bat demo/sahi_demo.sah http://sahi.co.in/demo/ ie testrunner.bat demo http://sahi.co.in/demo/ ie

To run your suite, use,
C:\sahi\userdata\bin>testrunner.bat myapp.suite http://myappdomain/startpage.jsp firefox

You can specify the browser you want to run it on. Browser names are defined in sahi/userdata/ browser_types.xml

Edit testrunner.bat to modify other parameters. testrunner.bat and testrunner.sh use the TestRunner java class internally.

Using ant

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

browserType can take any value defined in sahi/userdata/config/ browser_types.xml file.

Using Java TestRunner class

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

Usage:
————————————
New Usage 1:
java -cp /path/to/ant-sahi.jar net.sf.sahi.test.TestRunner -test <test_or_suite_name_or_folder_path> -browserType <browser_type> -baseURL <start_url> -threads <number_of_threads>

—- More options —-

-test path to test or suite, can also be a folder containing scripts
-baseURL baseURL for all tests
-threads no. of browser instances to run in parallel
-browserType browserType as specified in sahi/userdata/config/browser_types.xml
-browser full path to browser. Ignored if browserType specified.
-browserProcessName browser process name used to find the pid when using ps or tasklist commands. Ignored if browserType specified.
-browserOption Options to be passed to browser. Ignored if browserType specified.
-junitLog true or false. Enable or disable junit logs
-junitLogDir path to junit log dir. If not specified, uses default location in userdata/logs
-htmlLog true or false. Enable or disable html logs
-htmlLogDir path to html log dir. If not specified, uses default location in userdata/logs
-initJS Any javascript which would be executed before every script
-useSingleSession true or false. If true runs all scripts in a single browser without closing it between scripts
-extraInfo Any extra info that may be accessed using _extraInfo()

—- OR —-

Old Usage:
java -cp /path/to/ant-sahi.jar net.sf.sahi.test.TestRunner <test_or_suite_name_or_folder_path> <browser_executable> <start_url> <log_dir> <sahi_host> <sahi_port> <number_of_threads> <browser_executable> [<browser_option>]

Set log_dir to “default” to log to the default log dir
Set number_of_threads to a number which is compatible with your machine CPU and RAM.
————————————

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

For older documentation, please refer to Running multiple tests in batch mode




---


Top Rounds