Sahi is an automation and testing tool for web applications. Different from many other commercial testing tools, Sahi is an open source tool. As an automation tool, Sahi provides the facility of recording and play backing of scripts. Sahi supports Java and JavaScript. Even though the Sahi script looks like JavaScript, it is not executed as the regular JavaScript on the browser.

The basic idea of how Sahi work is described below.

HTML responses which pass through the proxy are modified such that JavaScript is injected at the start and the end of the response. This will allow the browser to record and playback scripts and talk back to the proxy when needed. Apart from handling requests for pages that the browser requests, Sahi also handles custom commands related to recording, playback etc. which the browser sends.

Besides the normal features like supporting ant, Sahi has its own features, like good support of database files, supporting JavaScript, AJAX and also the simple APIs.

Why Sahi

Compared to other web testing tools, Sahi controller (IDE) can be used in various browsers.

Sahi’s APIs do not depend much on the HTML structure. Sahi does not use XPaths and has APIs to help finding one element in relation to another. Even if the structure of the page changes, these work properly.

Installation and configuration

To install and configure Sahi:

  1. Download the latest build and unzip the file. Sahi requires Java 1.5 or later.
  2. Start Sahi’s proxy server. The startup scripts are in <sahi_root>\userdata\bin.For Windows: start_dashboard.bat
    • For Linux:
    • you can select a browser icon to start the browser you want to use.
    • For this example, we don’t need to be concerned about the browser configuration. Alternatively, Sahi provides GUI tools for you to start browsers. Run start_sahi.bat/ to start it, then click a browser icon to start the proxy server and browser process.

  3. Enter bat/, which is required for silent execution with the assistance of build tools such as Ant.

Recording testing scripts in Java format

Sahi provides two out-of-the-box script formats: Sahi and Java. You can modify the default option, which is Sahi, in <sahi_root>\config\ The Sahi format is a Java script-like format, running only within the Sahi Java script engine. The example in this article uses the more common Java format because the scripts can easily integrate with other testing tools and frameworks for large testing projects. The Java format involves a common Java code snippet that can be integrated with tools such as Junit and TestNG.

To run a brief test:

  1. Open the web application that you want to test. Press the ALT key and double-click on the page. (Firefox 3 was used for demonstration.)
  2. Select

    After selection, it will change to the Stop button.

  3. Do some operations in the web application, and then select Stop. All the steps you executed in the application are recorded.
  4. While your operations are recording, you can insert some assertions if you want. The tools also provide some options for insertions, but it is suggested you add them manually.

Test Suite

Multiple tests can be run through ant. For each test in the suite, the ant target opens a browser, runs the test and closes the browser. The ant target specifies a suite file, say SuiteName.suite.

Data Driven Testing

Sahi has some inbuilt features for data driven testing. Sahi can read and write to CSV (Comma Separated Value) files, databases and Excel sheets.

  • _readCSVFile (csvFilePath) reads a CSV file and returns a two dimensional array.
  • _writeCSVFile (array2D, filePath) writes the two dimensional array into a file in CSV format.