| 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

Using Sahi ·

Before you start – Flash Demo

Watch the flash demo. This will familiarize you with what follows.

Prerequisites

Java 1.5 or above is needed for running Sahi.

Download Sahi

Download Sahi V3 (2010-06-10) from SourceForge

Install Sahi

Unzip sahi.zip to a desired location

Start Sahi’s proxy:

Starting the Sahi proxy

Windows: – Go to <sahi_root>\userdata\bin and run start_sahi.bat
Linux – Go to <sahi_root>/userdata/bin and run start_sahi.sh

Note that by default Sahi uses port 9999. This can be modified through sahi.properties



Configure the browser:

You need to change your browser’s proxy setting to use Sahi’s proxy.

Firefox:

Configuring Firefox to use Sahi's proxy

  • Go to Tools > Options > General > Connection Settings >
  • Set to “Manual Proxy Configuration”
  • Set “HTTP Proxy” to “localhost”
  • Set “Port” to “9999”. (This setting can be modified through /config/sahi.properties)
  • Do the same for “SSL Proxy” too, if you wish to record and playback https sites
  • Keep “Use the same proxy for all protocol” unchecked as Sahi does not understand protocols other than HTTP
  • NOTE: “No Proxy for” should NOT have localhost in it.

Internet Explorer:

Configuring Firefox to use Sahi's proxy

  • Go to Tools > Internet Options > Connections > LAN Settings >
  • In “Proxy server” section, Check “Use a proxy server for your LAN
  • Click on “Advanced”
  • For HTTP: set “Proxy address to use” to “localhost” and set “Port” to “9999”
  • For Secure: set “Proxy address to use” to “localhost” and set “Port” to “9999” (if you want to test https sites too)
  • Clear out anything in “Do not use proxy server for addresses beginning with:”
  • OK
  • Leave “Bypass proxy server for local addresses” unchecked
  • OK > OK

Recording through Sahi

Sahi Controller - Recorder tab

  • Press ALT and double click on the window which you want to record. Sahi’s Controller window will pop up. (If that does not work, press CTRL and ALT keys together and then double click. Make sure popup blockers are turned off. For further trouble shooting have a look at this help link.)
  • On the Controller, go the the Record tab (would be selected by default).
  • Give a name for the script, and click ‘Record’
  • Navigate on your website like you normally would. Most actions on the page will now get recorded.
  • Add an assertion:
    • Move the mouse over any html element while pressing Ctrl key. The Accessor field will get populated in the Controller.
    • Click the “Assert” button to generate assertions for the element. They will appear in the “Evaluate Expression” box.
    • Click “Test —>” to check that the assertions are true. You can evaluate any javascript using “Evaluate Expression” and “Test —>”. Actions performed via the Controller will not be automatically recorded. Only actions performed directly on the page are automatically recorded. This lets you experiment on the webpage at recording time with out impacting the script.
    • Once satisfied, click on “Append to Script”. This will add the assertions to the Script.
  • Click “Stop” to finish recording.

Note that the Controller can be closed and reopened at any time, without disrupting recording.

View the recorded script

Sahi Controller - Recorder tab

The recoded script can be viewed and edited by opening the .sah file in the <sahi_root>\userdata\scripts directory. Sahi scripts are simple text files which use Javascript syntax.

The script can be edited even while recording, so that logical segregation into functions etc. can be done as recording happens.

Playing back

Sahi Controller - Playback tab

  • Open the Sahi Controller (CTRL-ALT-DblClick on the page).
  • Enter the script name in the “File:” field (with the help of the autocompletion feature).
  • Enter the Start URL of the test. If you had started recording from http://www.google.co.in, use that URL.
  • Click ‘Set’.
  • Wait for the page to reload.
  • Click ‘Play’.

Steps will start executing, and the Controller will be updated accordingly. Once finished, SUCCESS or FAILURE will be displayed at the end of the steps.

Note that the Controller can be closed at any time, without disrupting playback.

View Logs

Playback logs for single script run via Controller

On the Controller, go to Playback tab and click on “View Logs” link at the bottom right. It will open a window with the results neatly formatted in HTML.

Clicking on a line in the logs will drill down to exact line in script.

You can also view the logs at http://localhost:9999/logs

That is it! You have successfully recorded and played back a Sahi script!

---

Running a test from command line

There are sample scripts available in sahi/userdata/bin directory for running tests on various browsers.
To run firefox, edit ff.bat, make sure that the BROWSER and START_URL point to the correct values and run it as:
ff.bat <sah file|suite file>
Eg.
ff.bat demo/demo.suite
ff.bat demo/sahi_demo.sah

Similar files exist as ie.bat, chrome.bat etc.

Automating playback of multiple scripts

You can run multiple scripts in batch mode.
More information here

Trouble shooting

Tutorials

An excellent tutorial by StringyLow
Flash tutorial




---