Skip to content
Get Free Trial

Sahi Script

What Sahi Script is, what a script looks like, and how Sahi runs it.

Sahi Script is Sahi Pro’s scripting language, for the complex, domain-specific scenarios that no-code can’t cover. It has the same syntax as JavaScript, except that variables start with a $ sign.

A login-and-checkout test in Sahi Script:

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 same test, split into a test file and a library of reusable functions:

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);
}

Sahi parses each script and automatically adds reporting, waiting, language translation and error recovery. The result is fully valid JavaScript, which runs in a Rhino JavaScript engine inside Sahi’s proxy, in its Java Virtual Machine (JVM). Only the statements that act on the browser are sent to the browser. Everything else runs in Rhino.

So Sahi Script can call Java code directly: any Java code on Sahi’s classpath. Rhino passes variables between Java and JavaScript automatically.