Sahi Pro - Sahi Script


Sahi Script is Sahi's scripting language. It has the same syntax as Javascript except that variables need to be prefixed with a $ sign.

Sample Code

A simple sample script looks like this:

sample.sah
_setValue(_textbox("user"), "test");
_setValue(_password("password"), "secret");
_click(_submit("Login"));
_setValue(_textbox("q"), "2");
_setValue(_textbox("q[1]"), "1");
_setValue(_textbox("q[2]"), "1");
_click(_button("Add"));
_click(_cell("Rs.200[1]"));
_assertExists(_textbox("total"));
_assert(_isVisible(_textbox("total")));
_assertEqual("1150", _textbox("total").value);
_click(_button("Logout"));

The script broken into two files with functions looks like this:

sample.sah
_include("library.sah");

login("test", "secret");
addBooks(2, 1, 1);
verifyTotal(1150);

_click(_button("Logout"));

library.sah
function login($username, $password){
  _setValue(_textbox("user"), $username);
  _setValue(_password("password"), $password);
  _click(_submit("Login"));
}

function addBooks($numJava, $numRuby, $numPython){
  _setValue(_textbox("q"), $numJava);
  _setValue(_textbox("q[1]"), $numRuby);
  _setValue(_textbox("q[2]"), $numPython);
  _click(_button("Add"));
}

function verifyTotal($total){
  _assertEqual($total, _textbox("total").value);
}

Parsing and Execution

Sahi Script is parsed and modified to automatically include logging, waiting, error recovery etc.
The modified script is fully valid Javascript which is executed in a Rhino engine in the proxy's JVM.
Since Sahi code is executed via Rhino, Sahi script can call any java code in Sahi's classpath.
Rhino seamlessly translates variables between Java and Javascript.

Rhino Engine

Sahi's Javascript is executed in a Rhino Javascript Interpreter, running inside Sahi's proxy. Only relevant individual statements
are sent to the browser for execution. The rest of the runtime happens in Rhino inside Sahi's proxy.

Rhino is a Javascript runtime running inside a Java Virtual Machine (JVM). This adds a lot of power to Sahi scripts.
Sahi scripts can directly call Java code in scripts.