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:

_setValue(_textbox("user"), "test");
_setValue(_password("password"), "secret");
_setValue(_textbox("q"), "2");
_setValue(_textbox("q[1]"), "1");
_setValue(_textbox("q[2]"), "1");
_assertEqual("1150", _textbox("total").value);

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


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


function login($username, $password){
  _setValue(_textbox("user"), $username);
  _setValue(_password("password"), $password);

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

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

Parsing and Execution

Sahi Script is parsed and modified to automatically include logging, waiting, language translation, 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.

Also Refer:
Sahi APIs
Sahi Scripting