Sahi script is based on javascript. Sahi script is parsed by the proxy and the parsed script is fully valid javascript which is executed by the rhino javascript engine. Below are the normal constructs used in Sahi script. They are the same as javascript except for the mandatory $ used in variables.
Statements are normal lines of code. They end with a semi-colon.
Eg.
_click(_link("Login"));
var $variableName = value;
or
var $variableName; // declaration $variableName = value; // assignment
Eg.
var $username = "SahiTestUser"; var $password; // declaration; $password = $username + "_password"; // "SahiTestUser_password"
function functionName($parameter1, $parameter2) {
// statements
}
Eg.
// function declaration
function login($usr, $pwd){
_click(_link("Login"));
_setValue(_textbox("username"), $usr);
_setValue(_password("password"), $pwd);
_click(_submit("Login"));
}
// function call
login("sahi_user", "secret");
// This is a single line comment
/* This is a multiline comment. This has two lines */
if (condition) {
// statements
}
Eg.
if ($username == "PartnerUser"){
_click(_link("Partner Login"));
}
for (var $i=0; $i<$max; $i++){
// statements
}
Eg.
// This loop will login with user1, password1, user2, password2 etc.
// login and logout are custom functions.
for (var $i=0; $i<10; $i++){
login("user"+$i, "password"+$i);
logout();
}
while (condition) {
// statements
}
Eg.
$i = 0;
while ($i++ < 10) {
login("user"+$i, "password"+$i);
logout();
}
Use _include to include another Script file.
Eg.
_include("includes/common_functions.sah");