-
_abbr(identifier, domRelation)
-
Returns a handle to html element with 'abbr' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_above(accessor)
-
_above is a DOM relation marker which specifies that the element should be searched above another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_aboveOrUnder(accessor)
-
_aboveOrUnder is a DOM relation marker which specifies that the element should be searched either above or under another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_accessor(string) → {Node}
-
This API just evaluates the string and returns a dom object.
This API is not too useful.
Parameters:
| Name |
Type |
Description |
string |
string
|
Any string to be evaluated |
Returns:
Dom object
-
Type
-
Node
Example
_accessor("document.formName.elementName").
-
_activeElement()
-
Returns the element which is in focus.
-
_addMock(pattern, class_method)
-
Forces the proxy to process certain patterns of urls differently. If class_method is not specified, sends back a simple HTML blank page. If _addMock("pattern") is called without a second parameter, net.sf.sahi.command.MockResponder.simple(HttpRequest) is used to process the request. This response uses template at sahi/htdocs/spr/simpleMock.htm. One can modify this to show a generic mock response. By default this response just shows the mocked url.
Parameters:
| Name |
Type |
Description |
pattern |
string
|
The pattern of the URL |
class_method |
string
|
The class and method that will delegate the reponse handling |
Example
_navigateTo("http://sahi.co.in/demo/index.htm");
// assert a particular link exists on that page
_assertNotNull(_link("Link Test"));
// add mock
_addMock(".*sahi[.]co[.]in.*");
_navigateTo("http://sahi.co.in/demo/index.htm", true);
// link should not exist
_assertNull(_link("Link Test"));
// Instead the page contains the mocked url
_assert(_containsText(document.body, "http://sahi.co.in/demo/index.htm"));
-
_alert(message)
-
Brings up a javascript alert with given message. Use only while debugging
Parameters:
| Name |
Type |
Description |
message |
string
|
The message that is to be displayed |
Example
//displays a javascript alert with message "hello there!"
_alert("hello there!");
-
_applet(identifier, domRelation)
-
Returns a handle to html element with 'applet' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_area(identifier, domRelation)
-
Returns a handle to html element with area tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
id, title|alt, href, shape, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_assert(condition, message)
-
_assert will do nothing if the condition passed to it is true
_assert will log failures to the playback logs if the condition evaluates to false.
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and throws an exception if the condition is false
Parameters:
| Name |
Type |
Description |
condition |
boolean
|
Boolean expression |
message |
string
|
Message to be written to logs if condition was true |
Examples
// does nothing
_assert(1==1);
// and writes "Some Log Message" to logs.
_assert(1==2, "Some Log Message");
-
_assertContainsText(expectedText, element, message)
-
_assertContainsText will assert that an element contains the given text_assertContainsText will log failures to the playback logs if the condition evaluates to false.DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and throws an exception if the condition is false
Parameters:
| Name |
Type |
Description |
expectedText |
string
|
Text expected to be present. This can be replaced with a regular expression. |
element |
element
|
html dom element on where the text is to be found |
message |
string
|
Message to be written to logs if text was not present |
Examples
_assertContainsText("Invalid Login", _div("login_section"), "Text was not present");
_assertContainsText(/Invalid/i, _div("login_section"), "Text was not present");
_assertContainsText("Invalid Login", _div("login_section"));
_assertContainsText(/Invalid/i, _div("login_section"));
-
_assertEqual(expected, actual, message)
-
This is a browser Action API. It asserts that expected and actual are equal, else logs the message. If the expected and actual are equal, it will do nothing.
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and logs the message if the expected and actual values are not equal.
Parameters:
| Name |
Type |
Description |
expected |
string
|
Expected value |
actual |
string
|
Actual value |
message |
string
|
Message to be written to logs if the expected and actual values are not equal |
Examples
//does nothing
_assertEqual("abc", "abc", "Some Log Message");
//writes "Some Log Message" to logs.
_assertEqual("abc", "def", "Some Log Message");
-
_assertEqualArrays(expected, actual, message)
-
Asserts that expected and actual arrays are equal, else logs the message. This is internally called by _assertEqual if expected and actual are arrays.
Parameters:
| Name |
Type |
Description |
expected |
Array
|
Expected array |
actual |
Array
|
Actual array |
message |
string
|
Message to be logged |
- Deprecated:
-
_assertExists(object, message)
-
Asserts that the object is not null, else logs the message.
Parameters:
| Name |
Type |
Description |
object |
element
|
the object to be tested |
message |
string
|
The message to be logged |
-
_assertFalse(condition, message)
-
_assertFalse will do nothing if the condition passed to it is false
_assertFalse will log failures to the playback logs if the condition evaluated to true.
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and throws an exception if the condition is true
Parameters:
| Name |
Type |
Description |
condition |
boolean
|
Boolean expression |
message |
string
|
Message to be written to logs if condition was true |
Examples
// does nothing
_assertFalse(1==2);
// and writes "Some Log Message" to logs.
_assertFalse(1==1, "Some Log Message");
-
_assertNotContainsText(expectedText, object, message)
-
Asserts that the object does not contain the expectedText, else logs the message.
Parameters:
| Name |
Type |
Description |
expectedText |
string
|
The text against which the check is to be done |
object |
object
|
The DOM object whose text is to be checked |
message |
string
|
The error message to be logged in case of failure |
-
_assertNotEqual(expected, actual, message)
-
This is a browser Action API. It asserts that expected and actual are NOT equal, else logs the message. If the expected and actual are NOT equal, it will do nothing.
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and logs the message if the expected and actual values are equal.
Parameters:
| Name |
Type |
Description |
expected |
string
|
Expected value |
actual |
string
|
Actual value |
message |
string
|
Message to be written to logs if the expected and actual values are equal |
Examples
//does nothing
_assertNotEqual("abc", "def", "Some Log Message");
//writes "Some Log Message" to logs.
_assertEqual("abc", "abc", "Some Log Message");
-
_assertNotExists(object, message)
-
Asserts that the object does not exist (is null), else logs the message.
Parameters:
| Name |
Type |
Description |
object |
element
|
the object to be tested |
message |
string
|
The message to be logged |
-
_assertNotNull(object, message)
-
_assertNotNull will do nothing if the object passed to it is not null. (Object exists)
_assertNotNull will log failures to the playback logs if the object is null. (Object does not exist)
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and throws an exception if the object is null.
Parameters:
| Name |
Type |
Description |
object |
object
|
Any object |
message |
string
|
Message to be logged |
Examples
//Does nothing
_assertNotNull("abc");
//Writes "some log message" to the playback logs
_assertNotNull(null, "some log message");
-
_assertNotTrue(condition, message)
-
_assertNotTrue will do nothing if the condition passed to it is not true
_assertNotTrue will log failures to the playback logs if the condition evaluates to true.
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and throws an exception if the condition is true
Parameters:
| Name |
Type |
Description |
condition |
boolean
|
Boolean expression |
message |
string
|
Message to be written to logs if condition was true |
Examples
// does nothing
_assertNotTrue(1==2);
// and writes "Some Log Message" to logs.
_assertNotTrue(1==1, "Some Log Message");
-
_assertNull(object, message)
-
_assertNull will do nothing if the object passed to it is null. (Object does not exist)
_assertNull will log failures to the playback logs if the object is not null. (Object exists)
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and throws an exception if the object is not null.
Parameters:
| Name |
Type |
Description |
object |
object
|
Any object |
message |
string
|
Message to be written to logs if condition was true |
Examples
// does nothing
_assertNull(null);
// and writes "Some Log Message" to logs.
_assertNull("abc", "Some Log Message");
-
_assertTrue(condition, message)
-
_assertTrue will do nothing if the condition passed to it is true
_assertTrue will log failures to the playback logs if the condition evaluates to false.
DO NOT USE THIS IN AN IF CONDITION as it does not return any value, and throws an exception if the condition is false
Parameters:
| Name |
Type |
Description |
condition |
boolean
|
Boolean expression |
message |
string
|
Message to be written to logs if condition was true |
Examples
// does nothing
_assertTrue(1==1);
// and writes "Some Log Message" to logs.
_assertTrue(1==2, "Some Log Message");
-
_blockquote(identifier, domRelation)
-
Returns a handle to html element with 'blockquote' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_blur(element)
-
Removes focus from an element
Parameters:
| Name |
Type |
Description |
element |
element
|
The html element from which the focus is to be removed |
Example
//Removes focus from text box identified as _textbox("abc") by Sahi
_blur(_textbox("abc"));
-
_bold(identifier, domRelation)
-
Returns a handle to html element with 'b' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
-
Returns a handle to html element with 'button' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, value, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_byClassName(identifier, tagName, DOMRelation) → {Node}
-
Returns a handle to the html element with given class name and tag name and optionally with DOM relations
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
The class name which is to be considered |
tagName |
string
|
|
Tag in which the class is to be checked |
DOMRelation |
string
|
<optional>
|
The relation with other elements in DOM |
Returns:
A handle to the element
-
Type
-
Node
-
_byId(id) → {Node}
-
This can be used for any tag with an id. This API does not accept regular expressions or indexes.
Parameters:
| Name |
Type |
Description |
id |
string
|
ID of the element to get a handle of |
Returns:
A handle to the element with give Id
-
Type
-
Node
-
_bySeleniumLocator(seleniumLocater) → {Node}
-
identify element using any selenium identifier.
Parameters:
| Name |
Type |
Description |
seleniumLocater |
string
|
Any selenium locater |
Returns:
A handle to the element
-
Type
-
Node
Example
//identifies an element using xpath
_bySeleniumLocator(xpath)
-
_byText(identifier, tagName) → {Node}
-
This can be used for any tag with text to get a handle to that element
Parameters:
| Name |
Type |
Description |
identifier |
string
|
The text which is to be used as identifier |
tagName |
string
|
Name of the tag which is to be looked up |
Returns:
A handle to the element with given text
-
Type
-
Node
-
_byXPath(xpath, domRelation)
-
Returns a handle to html element with given xpath and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
xpath |
string
|
|
xpath expression as string |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_call(javascript)
-
_call is used execute javascript on the browser. _call should be used sparingly and only if none of the inbuilt Sahi Browser Action APIs work.
Parameters:
| Name |
Type |
Description |
javascript |
javascript
|
The JS code sippet to be executed on the browser |
Example
//executes the JS function on the browser
<browser>
function toggleTreeWidget(){
// some javascript to toggle a tree widget
}
</browser>
_call(toggleTreeWidget());
_call(location.href = "xxx");
-
_callServer(cmd, qs)
-
Calls server side code which cannnot be executed by javascript on the browser.
Parameters:
| Name |
Type |
Description |
cmd |
string
|
String command of the form "className_methodName" |
qs |
string
|
QueryString to be made available in the invoked method |
- Deprecated:
-
_cell(identifier, domRelation)
-
Returns a handle to html element with 'td' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_check(checkBoxOrRadioElement)
-
Checks the given checkbox or radio element. If already checked, this API does not do anything.
Parameters:
| Name |
Type |
Description |
checkBoxOrRadioElement |
element
|
The check box or Radio element to check |
-
_checkbox(identifier, domRelation)
-
Returns a handle to html element with 'checkbox' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_clearLastAlert()
-
Clears the value returned by _lastAlert().
-
_clearLastConfirm()
-
Clears the value returned by _lastConfirm().
-
_clearLastDownloadedFileName()
-
Clears the _lastDownloadedFileName (so that new files downloaded with the same fileName can be asserted)
-
_clearLastPrompt()
-
Clears the value returned by _lastPrompt().
-
_clearPrintCalled()
-
resets the value of _printCalled
-
_click(element, combo)
-
_click simulates a user's click on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
HTML Element to click |
combo |
string
|
<optional>
|
Any combo key. Can be "CTRL", "SHIFT", "ALT" or "META"; Can also be two or more keys together like "CTRL|SHIFT" |
Example
//Clicks button "Click Me"
_click(_button("Click Me"));
//clicks with CTRL key pressed
_click(_button("Click Me"), "CTRL");
//clicks with CTRL and SHIFT keys pressed
_click(_button("Click Me"), "CTRL|SHIFT");
-
_closeBrowser()
-
Closes a browser in the middle of script
Example
//Closes a browser in the middle of a script
_closeBrowser();
-
_closeWindow()
-
Closes the current window. This will work only for popups.
Example
_popup("popWin")._closeWindow();
-
_code(identifier, domRelation)
-
Returns a handle to html element with 'code' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_collect(apiType, id, inEl)
-
Collects all elements of a particular type and stores them in an array.
Parameters:
| Name |
Type |
Argument |
Description |
apiType |
string
|
|
The API for html elements to be collected |
id |
string
|
|
identifier for the elements to be collected |
inEl |
string
|
<optional>
|
location from where the elements are to be collected |
Example
//collects all the links in 'div1' with id containting 'group 1' and stores in $els
var $els = _collect ("_link", "/group 1/", _in(_div("div1")));
-
_confirm(message)
-
Brings up a javascript confirm with given message. Use only while debugging
Parameters:
| Name |
Type |
Description |
message |
string
|
The message to be displayed on the confirm window |
-
_contains(parentElement, childElement)
-
Returns true if childElement is a child of parentElement
Parameters:
| Name |
Type |
Description |
parentElement |
element
|
The container element |
childElement |
element
|
The element contained |
-
_containsHTML(element, html)
-
Returns true if the element contains the given html
Parameters:
| Name |
Type |
Description |
element |
element
|
The element in which the text is to be checked |
html |
string
|
The html to be tested |
Example
//returns true given div has the html "some"
_containsHTML(_div("divId"), "some")
-
_containsText(element, text)
-
Returns true if the element contains the given text
Parameters:
| Name |
Type |
Description |
element |
element
|
The element in which the text is to be checked |
text |
string
|
The text to be tested |
Example
//returns true given div has the text "some"
_containsText(_div("divId"), "some")
-
_continueOnError()
-
Makes script continue inspite of errors. Can be turned off with _stopOnError()
-
_cookie(cookieName)
-
Returns the value of the cookie with cookieName.
Parameters:
| Name |
Type |
Description |
cookieName |
string
|
The neame of cookie |
-
_count(apiType, id, inEl)
-
Counts all elements of a particular type and stores them in an array.
Parameters:
| Name |
Type |
Argument |
Description |
apiType |
string
|
|
The API for html elements to be counted |
id |
string
|
|
identifier for the elements to be counted |
inEl |
string
|
<optional>
|
location from where the elements are to be counted |
Example
//counts all the links in 'div1' with id containting 'group 1' and stores in $count
var $count = _count ("_link", "/group 1/", _in(_div("div1")));
-
_createCookie(name, value, days)
-
Creates a cookie with name and value which will expire in given days.
Parameters:
| Name |
Type |
Description |
name |
string
|
name of cookie |
value |
string
|
Value of cookie |
days |
integer
|
days for which cookie is to remain |
-
_dataDrive(fn, data2dArray)
-
Loops over data2DArray, and invokes function fn with each row of data. The invocation is within a try catch block with exception logging. The core concept is that data is present as a grid of rows and columns, and tests need to run with each row of the grid as input.
Parameters:
| Name |
Type |
Description |
fn |
string
|
The funtion name(without brackets) to be executed with data array |
data2dArray |
array
|
A two dimensional array of data which is used by function |
Example
//executes doAdd with each row in $data
function doAdd($first, $second, $total){
_setValue(_textbox("first"), $first);
_setValue(_textbox("second"), $second);
_click(_button("Add"));
_assertEqual($total, _textbox("total").value);
}
var $data = [
[2, 3, 5],
[1, 2, 4],
[4, 3, 7]
]
_dataDrive(doAdd, $data);
-
_datebox(identifier) → {Node}
-
Returns an accesor for form element of type date
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_datetimebox(identifier) → {Node}
-
Returns an accesor for form element of type datetime
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_datetimelocalbox(identifier) → {Node}
-
Returns an accesor for form element of type="datetime-local"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_dDesc(identifier, domRelation)
-
Returns a handle to html element with 'dd' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_debug(message)
-
Prints the message on to the console for debugging purposes.
Parameters:
| Name |
Type |
Description |
message |
string
|
The message to be displayed on console |
-
_debugToErr(message)
-
Prints the message on to the error stream for debugging purposes.
Parameters:
| Name |
Type |
Description |
message |
string
|
The message to be displayed |
-
_debugToFile(message, filepath)
-
Prints the message into a file for debugging purposes.
Parameters:
| Name |
Type |
Description |
message |
string
|
The message to be written in the file |
filepath |
string
|
path of the file to be written |
-
_deleteCookie(name)
-
Deletes cookie with given name.
Parameters:
| Name |
Type |
Description |
name |
string
|
name of cookie |
-
_deleteFile(filepath)
-
Deletes the file at filePath.
Parameters:
| Name |
Type |
Description |
filepath |
string
|
path of the file to be deleted |
-
_disableKeepAlive()
-
_disableKeepAlive() turns off Keep-Alive. It is used in conjunction with _enableKeepAlive() on pages which hang because of flash objects or applets.
Example
_disableKeepAlive();
_call(loadPageWithFlashWhichHangsOtherwise());
_enableKeepAlive();
-
_div(identifier, domRelation)
-
Returns a handle to html element with 'div' tag and given identifier and optionally domRelation. It is used to identify rows with text. Useful to look for cells in a row.
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
id, className, text, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_dList(identifier, domRelation)
-
Returns a handle to html element with 'dl' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_domain(identifier)
-
Returns a handle to the element in different domain. _domain() is used as a prefix to statements which need to be executed on another domain but are in the same base window.
Parameters:
| Name |
Type |
Description |
identifier |
string
|
Domain name |
Example
//Clicks on a link present in same base window but coming from www.tytosoftware.com
_domain("www.tytosoftware.com")._click(_link("Link Test"));
-
_doubleClick(element, combo)
-
simulates a user's double click on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
Element on which user double click is to be simulated |
combo |
string
|
<optional>
|
Any combo key; can be "CTRL", "SHIFT", "ALT" or "META"; Can also be two or more keys together like "CTRL|SHIFT" |
Examples
//Double clicks on button
_doubleClick(_button("Double Click Me"));
//doubleClicks with CTRL key pressed
_doubleClick(_button("Double Click Me"),"CTRL");
//doubleClicks with CTRL and SHIFT keys pressed
_doubleClick(_button("Double Click Me"), "CTRL|SHIFT");
-
_dragDrop(element, element)
-
simulates a drag and drop action.
Parameters:
| Name |
Type |
Description |
element |
element
|
HTML element to be dragged |
element |
element
|
HTML Element where the draggable will be dropped. |
Example
//will drag the item and drop it in the shopping cart
_dragDrop(_image("item"), _byId("ShoppingCart"));
-
_dragDropXY(draggable, x, y, isRelative)
-
Drags elementToDrag and drops it on the given x, y coordinates. If isRelative is true, drags x,y pixels relative to current position. If isRelative is false, drags to x,y coordinate on browser.
Parameters:
| Name |
Type |
Argument |
Description |
draggable |
element
|
|
HTML Element to be dragged |
x |
integer
|
|
x coordinate of drop point on the page |
y |
integer
|
|
y coordinate of drop point on the page |
isRelative |
boolean
|
<optional>
|
Specifies whether the coordinates are relative to current position of draggable element |
Examples
//If _image("item") is located at coordinates (50, 150), it will drag the item and drop it at the coordinate (100, 300)
_dragDropXY(_image("item"), 100, 300);
//If _image("item") is located at coordinates (50, 150), it will drag the item and drop it at the coordinate (50+100, 150+300)
_dragDropXY(_image("item"), 100, 300, true);
-
_dTerm(identifier, domRelation)
-
Returns a handle to html element with 'dt' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_dynamicInclude()
-
Includes a file at runtime based on conditions provided by user in script.
-
_emailbox(identifier) → {Node}
-
Returns an accesor for form element of type="email"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_emphasis(identifier, domRelation)
-
Returns a handle to html element with 'em' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_enableKeepAlive()
-
_enableKeepAlive() turns on Keep-Alive. It is used in conjunction with _disableKeepAlive() on pages which hang because of flash objects or applets.
Example
_disableKeepAlive();
_call(loadPageWithFlashWhichHangsOtherwise());
_enableKeepAlive();
-
_eval(string)
-
eval is used to eval a string on the browser.
Parameters:
| Name |
Type |
Description |
string |
string
|
The string to eval on the browser |
Example
//Evals the string directly on browser
_eval("document.form1.complicatedWidget.click()");
-
_execute(command, isSynchronous)
-
It can be used to run batch or shell scripts. It internally does a java Runtime.exec()
Parameters:
| Name |
Type |
Description |
command |
string
|
Command to be executed |
isSynchronous |
boolean
|
Set this to true if you want the script to wait till the process returns. Setting this to false will execute the command in a thread and continue. |
Example
//Executes someAction.bat file
_execute("someAction.bat");
-
_exists(element)
-
Returns true if the element exists. Same as checking element != null.
Parameters:
| Name |
Type |
Description |
element |
element
|
element whose existence is to be checked |
Returns:
true if element exists
-
_expectConfirm(label, value)
-
Sets an expectation such that when a javascript confirm with given message appears, based on the boolean value, OK or Cancel will be processed. Javascript calls to confirm(msg) are mocked out by Sahi so that it does not stop playback.
Sahi by default acts as if "OK" was clicked when a confirm dialog comes up. It is possible to make the confirm return as if it was cancelled by setting the second parameter to false. If there was no expectation set, Sahi will return true.
Parameters:
| Name |
Type |
Description |
label |
string
|
The label of confirm box |
value |
boolean
|
Expected boolean return value |
- See:
-
-
_expectPrompt(label, value)
-
Javascript calls to prompt(msg) are mocked out by Sahi so that it does not stop the playback. Sahi by default returns "" if a prompt dialog comes up. It is possible to make the prompt return the value one wants, by specifying _expectPrompt(label, value);before the statement which triggers the prompt dialog. If there was no expectation set, Sahi will return "".
Parameters:
| Name |
Type |
Description |
label |
string
|
The visible text on the prompt dialog. |
value |
string
|
Value to be filled in the prompt |
- See:
-
-
_f()
-
Used to identify the objects in flex application.
-
_fail()
-
Aborts the scripts and exits.
-
_fetch()
-
Used to fetch the value of a page dependent variable (something that is part of the browser page) and store it in a Sahi variable.
Parameters:
| Name |
Type |
Description |
element.value |
string
|
Accesor for the element and the value which is to be fetched |
Example
//gets the value of textbox t1
var $text = _fetch(_textbox("t1").value);
-
_file(identifier, domRelation)
-
Returns a handle to html element with 'file' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_flex()
-
Same as _f(), used to identify the objects in flex application.
-
_focus(element)
-
Brings focus to element.
Parameters:
| Name |
Type |
Description |
element |
element
|
The element to be focused |
Example
//focuses text box identified as _textbox("abc") by Sahi
_focus(_textbox("abc"));
-
_focusWindow()
-
Brings the current window into focus above the other screens. Used with native events or screen shots. Currently works only on Windows.
Example
// brings window in focus and takes screen shot
_focusWindow();
_takeScreenShot();
-
_getAttribute()
-
Returns the attribute of a particular element.
-
_getCellText()
-
Same as _getText
- Deprecated:
-
_getDB(driver, jdbcurl, username, password, propertiesObj)
-
It is used to connect to a database.
Parameters:
| Name |
Type |
Description |
driver |
class
|
JDBC driver class |
jdbcurl |
string
|
JDBC URL |
username |
string
|
username to connect to the database |
password |
string
|
password to connect to the database |
propertiesObj |
object
|
A java.util.Properties object with relevant key values |
Examples
//getting a handle to database
var $db = _getDB("oracle.jdbc.driver.OracleDriver","jdbc:oracle:thin:@dbserver:1521:sid","username", "password");
//(since v4.3) Constructing through Properties file
var $props = new java.util.Properties();
$props.put("user", "scott");
$props.put("password", "tiger");
$props.put("internal_logon", "sysoper");
var $db = _getDB("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@dbserver:1521:sid", $props);
-
_getExcel(excelFilePath, sheetName)
-
Allows manipulation of Excel files. This is a replacement of the older way of accessing excel sheets using
Parameters:
| Name |
Type |
Description |
excelFilePath |
string
|
path to excel file |
sheetName |
string
|
name of the sheet to read |
-
_getGlobal(name)
-
_getGlobal gets a previously stored variable whose scope will span a session. Globals are used for persisting variables across multiple web pages.
Parameters:
| Name |
Type |
Description |
name |
string
|
Name of the global variable |
-
_getSelectedText(selectElement)
-
Returns the text of the selected option in a <select> tag
Parameters:
| Name |
Type |
Description |
selectElement |
element
|
The select element whose text is needed |
-
_getText(element)
-
Returns the innerText or textContent of an element.
Parameters:
| Name |
Type |
Description |
element |
element
|
html element with innertext |
Returns:
Text inside the element
-
_getValue()
-
Returns the Value of an element.
-
_heading1(identifier, domRelation)
-
Returns a handle to html element with 'h1' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
text, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_heading2(identifier, domRelation)
-
Returns a handle to html element with 'h2' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
text, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_heading3(identifier, domRelation)
-
Returns a handle to html element with 'h3' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
text, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_heading4(identifier, domRelation)
-
Returns a handle to html element with 'h4' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
text, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_heading5(identifier, domRelation)
-
Returns a handle to html element with 'h5' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
text, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_heading6(identifier, domRelation)
-
Returns a handle to html element with 'h6' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
text, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_hidden(identifier, domRelation)
-
Returns a handle to html form element with type="hidden" and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
text, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html form element
-
_highlight(element)
-
Highlights an element with a red border. Used for debugging purposes.
Parameters:
| Name |
Type |
Description |
element |
element
|
The html element to be highlighted |
Example
//Highlights div with id="abc"
_highlight(_div("abc"));
-
_iframe(identifier, domRelation)
-
Returns a handle to html element with 'iframe' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, id, name |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_image(identifier, domRelation)
-
Returns a handle to html element with 'img' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, title or alt, id, file name from src |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
-
Returns a handle to html element with 'img' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, tilte/alt, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_in(accessor)
-
_in is a DOM relation marker which specifies that the element should be searched inside another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_include(filePath)
-
_include lets one Sahi script to include another. This helps in organizing code.
Parameters:
| Name |
Type |
Description |
filePath |
string
|
Path of file to include. It can be absolute file path or a path relative to the file where the script is included. |
-
_isChrome()
-
Returns true if browser is Google Chrome
-
_isFF()
-
Returns true if browser is Mozilla Firefox
-
_isFF3()
-
Returns true if browser is Mozilla Firefox
-
_isFF4()
-
Returns true if browser is Mozilla Firefox
-
_isIE()
-
Returns true if browser is Internet Explorer
-
_isIE9()
-
Returns true if browser is Internet Explorer 9
-
_isIE10()
-
Returns true if browser is Internet Explorer 10
-
_isOpera()
-
Returns true if browser is Opera
-
_isSafari()
-
Returns true if browser is Safari
-
_isVisible(element)
-
Returns true if the element is visible on the user interface. Can be used to assert if a mouse over menu has appeared or not.
Parameters:
| Name |
Type |
Description |
element |
element
|
The element whose visibility is to be tested |
-
_italic(identifier, domRelation)
-
Returns a handle to html element with 'i' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_keyDown(element, charinfo, combo)
-
simulates doing a keyDown of a key on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
any HTML element |
charinfo |
string
|
|
charInfo can be:
- a character (eg. 'b')
- charCode of a character (eg. 98)
- an array of [keyCode, charCode] (eg. [13,13] for pressing ENTER key)
|
combo |
string
|
<optional>
|
can be any of "CTRL", "ALT", "SHIFT" or "META" |
Examples
_keyDown(document.body, 'a');
_keyDown(document.body, 'a', "CTRL");
-
_keyPress(element, charinfo, combo)
-
simulates pressing a keyboard key on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
any HTML element |
charinfo |
string
|
|
charInfo can be:
- a character (eg. 'b')
- charCode of a character (eg. 98)
- an array of [keyCode, charCode] (eg. [13,13] for pressing ENTER key)
|
combo |
string
|
<optional>
|
can be any of "CTRL", "ALT", "SHIFT" or "META" |
Examples
_keyPress(document.body, 'a');
_keyPress(document.body, 'a', "CTRL");
-
_keyUp(element, charinfo, combo)
-
simulates doing a keyUp of a key on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
any HTML element |
charinfo |
string
|
|
charInfo can be:
- a character (eg. 'b')
- charCode of a character (eg. 98)
- an array of [keyCode, charCode] (eg. [13,13] for pressing ENTER key)
|
combo |
string
|
<optional>
|
can be any of "CTRL", "ALT", "SHIFT" or "META" |
Examples
_keyUp(document.body, 'a');
_keyUp(document.body, 'a', "CTRL");
-
_label(identifier, DOMRelation) → {Node}
-
Returns a handle to the lable with given identifier and optionally DOM relation
Parameters:
| Name |
Type |
Description |
identifier |
string
|
id, index, text |
DOMRelation |
string
|
DOM relationship with another element |
Returns:
A handle to the element
-
Type
-
Node
-
_lastAlert()
-
Returns the message displayed in the last javascript alert popup.
-
_lastConfirm()
-
Returns the message displayed in the last javascript confirm popup.
-
_lastDownloadedFileName()
-
Returns the name of last downloaded file
-
_lastPrompt()
-
Returns the message displayed in the last javascript prompt popup.
-
_leftOf(accessor)
-
_leftOf is a DOM relation marker which specifies that the element should be searched to the left of another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_leftOrRightOf(accessor)
-
_leftOrrightOf is a DOM relation marker which specifies that the element should be searched to the right or left of another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_link(identifier, domRelation)
-
Returns a handle to html element with 'a' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, visible text, id. |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_list(identifier, domRelation)
-
Returns a handle to html element with 'ul' or 'ol' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_listItem(identifier, domRelation)
-
Returns a handle to html element with 'li' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, id, name |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_log(message, type)
-
It is used to log into the playback logs. This is different from the debug methods which log messages to the standard output/error streams or into a file.
Parameters:
| Name |
Type |
Description |
message |
string
|
The message to be written in the logs |
type |
string
|
Changes the styling of log message where type can be "success", "failure", "error", "info" for different colors of bar and "custom", "custom1", "custom2" � "custom5" for different colors |
Examples
// shows up "Here" as a green bar in the playback log.
_log("Here", "success");
// shows up "Here" as a red bar in the playback log.
_log("Here", "failure");
// shows up "Here" as a red bar in the playback log.
_log("Here", "error");
// shows up "Here" without any colour, in the playback log.
_log("Here", "info");
// shows "Here" in a different color on the logs.
_log("Here", "custom");
-
_logException(exception)
-
Logs an exception. Used in catch block of try-catch.
Parameters:
| Name |
Type |
Description |
exception |
string
|
the exception to be logged |
-
_logExceptionAsFailure(exception)
-
Logs an exception and stops execution. Used in catch block of try-catch.
Parameters:
| Name |
Type |
Description |
exception |
string
|
the exception to be logged |
-
_map(identifier, domRelation)
-
Returns a handle to html element with 'map' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
name, id, title, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_maskLogs(startMsg)
-
Statements following _maskLogs($msg) will be masked in the logs. (A replacement text will be visible instead.) This is useful when password or other information should not be visible in logs. Masking can be toggled back using _unmaskLogs($endMsg). $startMsg and $endMsg are logged in the reports to help understand what has been masked.
Parameters:
| Name |
Type |
Description |
startMsg |
string
|
MEssage displayed in logs |
Example
_maskLogs("Password Information start");
_setValue(_password("password"), "secret");
_unmaskLogs("Password Information end");
-
_mockImage(pattern, class_method)
-
same as _addMock except that it by default calls net.sf.sahi.command.MockResponder.mockImage(HttpRequest) which returns a simple image at sahi/htdocs/spr/mock.gif
Parameters:
| Name |
Type |
Description |
pattern |
string
|
The pattern of the URL |
class_method |
string
|
The class and method that will delegate the reponse handling |
-
_monthbox(identifier) → {Node}
-
Returns an accesor for form element of type="month"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_mouseDown(element, isRight, combo)
-
simulates a mousedown on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
HTML Element to perform a mousedown on |
isRight |
boolean
|
<optional>
|
Set to true for a left-hand mouse |
combo |
string
|
<optional>
|
Any combo key; can be "CTRL", "SHIFT", "ALT" or "META"; Can also be two or more keys together like "CTRL|SHIFT" |
Examples
_mouseDown(_button("Mouse Down"));
//mouseDown for a left-hand mouse
_mouseDown(_button("Mouse Down"), true);
//mouseDown with CTRL key pressed
_mouseDown(_button("Mouse Down"), false, "CTRL");
//mouseDown with CTRL and SHIFT keys pressed
_mouseDown(_button("Mouse Down"), false, "CTRL|SHIFT");
-
_mouseOver(element, combo)
-
simulates mouse hovering on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
HTML Element to hover over |
combo |
string
|
<optional>
|
Any combo key. It can be "CTRL", "SHIFT", "ALT" or "META"; Can also be two or more keys together like "CTRL|SHIFT" |
Examples
//hovers on button "Click Me"
_mouseOver(_button("Click Me"));
// mouseOver with CTRL key pressed
_mouseOver(_button("Click Me"), "CTRL");
// mouseOver with CTRL and SHIFT keys pressed
_mouseOver(_button("Click Me"), "CTRL|SHIFT");
-
_mouseUp(element, isRight, combo)
-
simulates a mouseup on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
HTML Element to perform a mouseup on |
isRight |
boolean
|
<optional>
|
Set to true for a left-hand mouse |
combo |
string
|
<optional>
|
Any combo key; can be "CTRL", "SHIFT", "ALT" or "META"; Can also be two or more keys together like "CTRL|SHIFT" |
Examples
_mouseup(_button("Mouse up"));
//mouseup for a left-hand mouse
_mouseup(_button("Mouse up"), true);
//mouseup with CTRL key pressed
_mouseup(_button("Mouse up"), false, "CTRL");
//mouseup with CTRL and SHIFT keys pressed
_mouseup(_button("Mouse up"), false, "CTRL|SHIFT");
-
_navigateTo(URL, forceReload)
-
_navigateTo is used to navigate to a URL. This can be used as the first line in a test to set the start point. If the url is same as what is loaded on the browser, the page will be refreshed only if forceReload is true
Parameters:
| Name |
Type |
Argument |
Description |
URL |
string
|
|
The URL which is to be loaded |
forceReload |
boolean
|
<optional>
|
False by default. Set to true if reloading the same page is required |
Examples
//goes to URL "http://sahi.co.in"
_navigateTo("http://sahi.co.in");
//If already on http://sahi.co.in, it will force relaod the page
_navigateTo("http://sahi.co.in", true);
-
_near(accessor)
-
_near is a DOM relation marker which specifies that the element should be searched near another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_numberbox(identifier) → {Node}
-
Returns an accesor for form element of type="number"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_openBrowser()
-
Opens a browser in the middle of a script.
Example
//Opens a browser in the middle of a script
_openBrowser();
-
_openWindow(url, name, resolution)
-
Opens a browser with window name and in defined resolution.
Parameters:
| Name |
Type |
Argument |
Description |
url |
string
|
<optional>
|
Specifies the URL of the page to open. If no URL is specified, a new window with about:blank is opened |
name |
string
|
<optional>
|
Specifies the target attribute or the name of the window. |
resolution |
array
|
<optional>
|
Specifies window resolution. |
Example
//Opens a browser with window name and in defined resolution, can be use for less than 3 param
_openWindow("http://sahi.co.in", "defaultSahiPopup", [320,480]);
-
_option(identifier, domRelation)
-
Returns a handle to html element with 'option' tag and given identifier and optionally domRelation. It is used to identify rows with text. Useful to look for cells in a row.
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
id, className, text, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_paragraph(identifier, domRelation)
-
Returns a handle to html element with 'p' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_parentCell(element, occurrence) → {Node}
-
Returns the parent cell of an element
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
The element whose parent node needs to be found |
occurrence |
integer
|
<optional>
|
The nth parent. 1 is the immediate parent. |
Returns:
-
Type
-
Node
-
_parentNode(element, tagName, occurrence)
-
Returns the parent node of an element witg given tag
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
The element whose parent node needs to be found |
tagName |
string
|
|
The html tag whose parent is to be found |
occurrence |
integer
|
<optional>
|
The nth parent. 1 is the immediate parent. |
Example
//returns the first div parent of link
_parentNode(_link("aLink"), "DIV", 1)
-
_parentRow(element, occurrence) → {Node}
-
Returns the parent row of an element
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
The element whose parent node needs to be found |
occurrence |
integer
|
<optional>
|
The nth parent. 1 is the immediate parent. |
Returns:
-
Type
-
Node
-
_parentTable(element, occurrence) → {Node}
-
Returns the parent table of an element
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
The element whose parent node needs to be found |
occurrence |
integer
|
<optional>
|
The nth parent. 1 is the immediate parent. |
Returns:
-
Type
-
Node
-
_password(identifier, domRelation)
-
Returns a handle to html element with type= "password" and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_position(element)
-
Returns the an array with the element's x, y coordinate in pixels.
Parameters:
| Name |
Type |
Description |
element |
element
|
The element whose position is required |
-
-
Returns a handle to html element with 'pre' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_printCalled()
-
Returns true if window.print() had been invoked.
-
_prompt(message)
-
Brings up a javascript prompt with given message. Use only while debugging
Parameters:
| Name |
Type |
Description |
message |
string
|
The message to display |
-
_radio(identifier, domRelation)
-
Returns a handle to html element with type= "radio" and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_random(max) → {Number}
-
Returns a random number between 0 and max
Parameters:
| Name |
Type |
Description |
max |
number
|
The maximum number |
Returns:
The random number generated
-
Type
-
Number
-
_rangebox(identifier) → {Node}
-
Returns an accesor for form element of type="range"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_readCSVFile(filepath, separator)
-
Reads a csv file and returns a 2 dimensional array of the contents. If the separator between words is not a comma, it can be specified as the second parameter.
Parameters:
| Name |
Type |
Argument |
Description |
filepath |
string
|
|
path of the csv file |
separator |
string
|
<optional>
|
required only if the separator is not comma |
-
_readExcelFile(filepath, sheetname, ignoreHeader)
-
Reads an Excel file and returns a 2 dimensional array of the contents. If the first row is not desired, the third parameter can be set to false. This will ignore the header.
Parameters:
| Name |
Type |
Description |
filepath |
string
|
path to the excel file |
sheetname |
string
|
Name of the excel sheet |
ignoreHeader |
boolean
|
set false to ignore the first row |
-
_readFile(filepath)
-
_readFile is used to read text files. Returns the contents of the file as a single String.
Parameters:
| Name |
Type |
Description |
filepath |
string
|
Path of file to read. Can be relative to where Sahi was started from (sahi/bin in most cases) |
-
_readLayoutFile(filepath)
-
Reads the layout text file and return string
Parameters:
| Name |
Type |
Description |
filepath |
string
|
layout file path |
Example
//Read the layout text file and store it in the variable
var $data = _readLayoutFile("page_layout.txt");
-
_readURL(url)
-
Reads the content at the specified URL and returns its contents as a string
Parameters:
| Name |
Type |
Description |
url |
string
|
The URL to read |
-
_removeFocus(element)
-
Removes focus from an element
Parameters:
| Name |
Type |
Description |
element |
element
|
The html element from which the focus is to be removed |
Example
//Removes focus from text box identified as _textbox("abc") by Sahi
_removeFocus(_textbox("abc"));
-
_removeMock(pattern)
-
Removes the mock behavior added via _addMock or _mockImage for that pattern.
Parameters:
| Name |
Type |
Description |
pattern |
string
|
The pattern on which mock is to be removed |
-
_removeRecovery(fn)
-
Removes any recovery function which was set via _setRecovery.
Parameters:
| Name |
Type |
Description |
fn |
string
|
The recovery function name |
-
_renameFile(oldfilePath, newfilePath)
-
Renames (or moves) a given file from oldFilePath to newFilePath. If newFilePath already exists, it will be overwritten
Parameters:
| Name |
Type |
Description |
oldfilePath |
string
|
Path to old file |
newfilePath |
string
|
Path to new file |
-
_reset(identifier, domRelation)
-
Returns a handle to html element with 'reset' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_resetSavedRandom(id)
-
Resets the random number associated with key, to another random number.
Parameters:
| Name |
Type |
Description |
id |
string
|
Id of the _savedRandom that needs to be reset |
- Deprecated:
-
_resolvePath()
-
Returns the name of the current script
-
_rightClick(element, combo)
-
simulates a user's right click on the given element.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
Element on which user double click is to be simulated |
combo |
string
|
<optional>
|
Any combo key; can be "CTRL", "SHIFT", "ALT" or "META"; Can also be two or more keys together like "CTRL|SHIFT" |
Examples
//Right clicks on button
_rightClick(_button("Right Click Me"));
//Right clicks with CTRL key pressed
_rightClick(_button("Right Click Me"),"CTRL");
//Right clicks with CTRL and SHIFT keys pressed
_rightClick(_button("Right Click Me"), "CTRL|SHIFT");
-
_rightOf(accessor)
-
_rightOf is a DOM relation marker which specifies that the element should be searched to the right of another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_row(identifier, domRelation)
-
Returns a handle to html element with 'tr' tag and given identifier and optionally domRelation. It is used to identify rows with text. Useful to look for cells in a row.
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
id, className, text, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_rte(identifier, domRelation)
-
Returns a handle to html element with 'iframe' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, id, name |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_rteHTML(element)
-
Returns the html inside a rich text editor. Eg. _rteHTML(_rte("rteId")) will return the rich text editor's contents.
Parameters:
| Name |
Type |
Description |
element |
element
|
The rich text editor element |
-
_rteText(element)
-
Returns the text inside a rich text editor. Eg. _rteText(_rte("rteId")) will return the rich text editor's text content (without the html formatting).
Parameters:
| Name |
Type |
Description |
element |
element
|
The rich text editor element |
-
_rteWrite(iframe, text)
-
Writes text into a rich text editor based on content-editable iframe
Parameters:
| Name |
Type |
Description |
iframe |
element
|
The iframe in which the editor is present |
text |
string
|
The text to be written |
-
_runUnitTests()
-
_runUnitTests() executes all functions whose name starts with "test". If functions setUp() and tearDown() are defined, they are executed before and after each test, irrespective of errors in the test functions.
Examples
function setUp(){
_log("In setUp");
}
function tearDown(){
_log("In tearDown");
}
function testAddition() {
_assertEqual(3, 1+2);
}
function testSubtraction() {
_assertEqual(3, 5-2);
}
function testMultiplication() {
_assertEqual(8, 2*4);
}
// Invoke all tests:
_runUnitTests();
// Invoke only testAddition and testMultiplication
// Use this for debugging when you are fixing just one test
// and don't want to run all the tests.
_runUnitTests(["testAddition", "testMultiplication"]);
-
_saveDownloadedAs(filename)
-
Saves the file which was downloaded into sahi/temp/folder into the given filePath
Parameters:
| Name |
Type |
Description |
filename |
string
|
Name for the downloaded file |
-
_savedRandom(id, min, max)
-
_savedRandom stores a random number against an id and returns the same number for subsequent invocations in that session. The min and max parameters are only required during the first invocation. Defaults for min and max, if omitted, are 0 and 10000 for the first call for an id.
Parameters:
| Name |
Type |
Description |
id |
string
|
Any string that will be used to hold the number |
min |
number
|
Minimum limit |
max |
number
|
Maximum limit |
- Deprecated:
Example
//returns a random number between 100, 200; say 145.
_savedRandom("login", 100, 200);
//will return 145,
//since it was saved against the id "login".
//The min and max are redundant here.
_savedRandom("login", 100, 200);
//will also return 145.
_savedRandom("login");
-
_scriptName()
-
Returns the name of the current script
-
_scriptPath()
-
Returns script path of current script.
-
_scriptStartTime()
-
Returns the start time of the execution.
-
_scriptStatus()
-
Returns Success or Failure for current script
-
_searchbox(identifier) → {Node}
-
Returns an accesor for form element of type="search"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_select(identifier, domRelation)
-
Returns a handle to html element with select tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_selectDomain(identifier)
-
Returns a handle to the element in different domain.
_selectDomain(identifier) is used to select the domain for statements which need to be executed on another domain but are in the same base window.
_selectDomain() will return to the base domain
Parameters:
| Name |
Type |
Description |
identifier |
string
|
domain name to select |
Example
_selectDomain("www.tytosoftware.com")
_click(_link("Link Test"));
_setValue(_textbox("q"), "sahi forums");
_click(_submit("go"));
_selectDomain();
-
_selectWindow(popupId)
-
Sets the given window as context for the following Sahi statements. The identifier can be a regular expression. This API helps make scripting easier when most actions are performed on a popup window.
Parameters:
| Name |
Type |
Description |
popupId |
string
|
Id of the popup to select |
Example
// select popWin
_selectWindow("popWin");
// further statements will be performed on popWin
_click(_link("Click me")); // will click on popWin
_click(_button("Done")); // will click on popWin
_selectWindow(); // select base window
// further statements will be performed on base window
_click(_button("Finished")); // clicks on base window;
-
_sendHTMLResponseAfterFileDownload(boolean)
-
Sometimes a webpage may open a new window to show a PDF file. In this case, we need to ask Sahi to send a HTML response back.
Parameters:
| Name |
Type |
Description |
boolean |
boolean
|
set to true if you want to send a response back |
Example
_sendHTMLResponseAfterFileDownload(true);
_click(_link("Show PDF in new Window"));
if (_lastDownloadedFileName() != null) {
_saveDownloadedAs("test.pdf"); //Change this to whatever your download directory is
}
_clearLastDownloadedFileName();
// Close the newly opened window
_popup("/.* /")._closeWindow();
-
_sessionInfo()
-
Returns information of the current session. The object has attributes:
- isRecording: returns true if recording
- isPlaying: returns true if playingback
- isPaused: returns true if playback is paused
- sessionId: returns Sahi's sessionId
- threadNumber: returns the threadNumber of browser instance running
- scriptPath: returns script path of current script. Same as _scriptPath()
-
_set($variableName, value)
-
Used to fetch the value of a page dependent variable (something that is part of the browser page) and store it in a Sahi variable.
Parameters:
| Name |
Type |
Description |
$variableName |
string
|
variable to assign the value to |
value |
string
|
value to assign. Note that the value should not be a javascript object which has attributes which reference itself. |
Example
// sets the href of link to variable
var $href;
_set($href, _link("my link").href); // store
// you may do other actions or navigate to other pages
_assertEqual("http://sahi.co.in", $href); //use
-
_setFile(element, filePath, actionURL)
-
If there are javascript validations on the file field, you can try this hack. Before submitting the file, change the field's type to "text", and then set its value.
Parameters:
| Name |
Type |
Argument |
Description |
element |
element
|
|
HTML Form File Element whose value needs to be set |
filePath |
string
|
|
Path of the file to be uploaded. |
actionURL |
string
|
<optional>
|
The form action URL to which the file is submitted. This is an optional parameter. Use it in cases where the form's action URL is changed on setting the file. By default, it uses the form's current action URL. |
Examples
//sets the file efg.jpg for upload
_setFile(_file("id"), "C:\\abc\\efg.jpg");
//sets the file efg.jpg for upload at given action URL
_setFile(_file("id"), "C:\\abc\\efg.jpg", "formSubmit.jsp");
// set the file
_setFile(_file("file"), "scripts/demo/uploadme.txt");
// Change the "type" attribute of file field
if (_isIE()){
_call(_file("file").outerHTML = _file("file").outerHTML.replace(/type=['"]?file['"]?/, "type=text"));
}else{
_call(_file("file").type = "text");
}
// Set the value into the textbox
_setValue(_textbox("file"), "scripts/demo/uploadme.txt");
-
_setFlexReadyCondition()
-
Defines some conditions to be fulfilled before performing actions on a flex application.
-
_setGlobal(key, value)
-
Stores the value in key for retreival.The value persists across tests in a suite, if suite.global_variables is true in sahi.properties.
Parameters:
| Name |
Type |
Description |
key |
string
|
The key name through which the variable is accesible |
value |
string
|
Value corresponding to the key |
Example
//sets the value of userid1 as the value of _textbox("user")
_setGlobal("userid1", _textbox("user").value);
-
_setRecovery(fn)
-
Sets fn as recovery function. The function will be called before the script exists, if and only if there is a failure in the script. It can be turned off with _removeRecovery()
This is different from try-catch because we do not want the script to continue; we just want the state of our system to be restored to a sensible point.
Any function can be assigned to a script as a recovery function. Once set, if there is an error during execution, the recovery function will be called before the script stops.
Parameters:
| Name |
Type |
Description |
fn |
string
|
The recovery function name |
Example
* _navigateTo("http://sahi.co.in/demo/");
function myRecoveryFn(){
_alert("In myRecoveryFn."); // This statement will be alerted in case of script error.
}
_setRecovery(myRecoveryFn); // Set the myRecoveryFn as recovery function.
_click(_link("Link Test")); // Works normally
_click(_link("Bad Link"));
// This statement fails and causes myRecoveryFn to be called.
_alert("done");
// This statement will not be called, because script failed in the last statement.
-
_setSelected(element, Option's, isMultiple)
-
It is used to select an option from a select box.
Parameters:
| Name |
Type |
Description |
element |
element
|
The select element |
Option's |
string
|
array
|
text, id or index; can also pass an array of options for multi-select |
isMultiple |
boolean
|
true for multiselect, optional for single select |
Examples
_setSelected(_select("Age"), "28");
_setSelected(_select("color"), 1); // Selects the second option in a select box
_setSelected(_select("color"), "red"); // Selects red in a multiselect box
_setSelected(_select("color"), "blue", true); // Selects blue also in the multiselect box
_setSelected(_select("color"), ["red", "blue"]); // Unselects previous and selects red and blue in a multiselect box
_setSelected(_select("color"), [1,2,3]); // Unselects previous and selects the second, third and fourth options in a multiselect box
_setSelected(_select("color"), ["green", "yellow"], true); // Keeps previous options selected and selects "green" and "yellow" also
-
_setStrictVisibilityCheck(boolean)
-
This API is useful in cases where widgets are dynamically created at multiple locations but only one of them is visible at any given time.
During recording Sahi can be forced into either mode by choosing "Strict Visibility On" or "Strict Visibility Off" from the "Other Actions:" dropdown. Make sure you "Append to Script" to add it to the recorded script
Parameters:
| Name |
Type |
Description |
boolean |
boolean
|
set true to enable strict visibilty check |
Example
// make Sahi ignore elements which are not visible.
_setStrictVisibilityCheck(true);
// make sahi revert to original behavior of considering all elements in the DOM.
_setStrictVisibilityCheck(false);
-
_setValue(element, value)
-
It is used for assigning values to textboxes and textareas.
Parameters:
| Name |
Type |
Description |
element |
element
|
HTML form element whose value is to be set |
value |
strin
|
The value to be set |
Example
//populates textbox identified as _textbox("user") with Vivek
_setValue(_textbox("user"), "Vivek");
-
_setXHRReadyStatesToWaitFor(readyState)
-
Tells Sahi which AJAX ready states to wait for. By defaults Sahi waits for ready states 1, 2 and 3.
Parameters:
| Name |
Type |
Description |
readyState |
integer
|
The AJAX ready state to wait for |
Example
//This will wait only for AJAX ready states 2 and 3, but not 1.
_setXHRReadyStatesToWaitFor(2,3);
-
_simulateEvent(element, event)
-
Used to simulate an event on element.
Parameters:
| Name |
Type |
Description |
element |
element
|
element on which event is to be simulated |
event |
event
|
the event to be simulated |
- Deprecated:
-
_span(identifier, domRelation)
-
Returns a handle to html element with 'span' tag and given identifier and optionally domRelation. It is used to identify rows with text. Useful to look for cells in a row.
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
id, className, text, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_spandiv(identifier, domRelation)
-
Returns a handle to html element with 'span' or 'div' tag and given identifier and optionally domRelation. It is used to identify rows with text. Useful to look for cells in a row.
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
id, className, text, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
- Deprecated:
Returns:
A handle to html element
-
_stackTrace()
-
Returns the absolute path with reference to the present script.
-
_stopOnError()
-
Makes the script stop if an error occurs. This is the default behavior.
-
_strong(identifier, domRelation)
-
Returns a handle to html element with 'strong' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
sahiText, id, className, index |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_style(element, cssProperty)
-
Returns the value of the style property for that element.
Parameters:
| Name |
Type |
Description |
element |
element
|
Element whose property is used |
cssProperty |
string
|
CSS property to be used |
-
_submit(identifier, domRelation)
-
Returns a handle to html element with type= "submit" and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_suiteInfo()
-
Returns information of the current session. The object has properties:
- suiteName: name of suite
- suitePath: Path of suite
- base: Base url for suite
- browser: Browser executable path
- browserOption: browserOption passed to Suite
- browserProcessName: browserProcessName passed to Suite
- sessionId: SessionId of suite
-
_table(identifier, domRelation)
-
Returns a handle to html element with 'table' tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_takeScreenShot()
-
Takes a screen shot of the entire screen, and embeds image in reports. Use with _focusWindow to make sure the right window is in focus.
Example
//brings current window to focus and takes screenshot
_focusWindow();
_takeScreenShot();
-
_telephonebox(identifier) → {Node}
-
Returns an accesor for form element of type="tel"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_testcase(name, description)
-
used to define a testcase. Has two methods: start() and end() used to define the start and end of a testcase.
Parameters:
| Name |
Type |
Description |
name |
string
|
Name of the testcase |
description |
string
|
This description will be displayed in the logs |
Example
//defines a testcase called TC_1
var $t = _testcase("TC_1", "Login");
$t.start();
_setValue(_textbox("user"), "test");
_setValue(_password("password"), "secret");
_click(_submit("Login"));
$t.end();
-
_textarea(identifier, domRelation)
-
Returns a handle to html element with textarea tag and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_textbox(identifier, domRelation)
-
Returns a handle to html element with type="text" and given identifier and optionally domRelation
Identifiers can either be a numerical index or a property as specified in each case.
Identifiers which are not numerical, can either be a string or a javascript regular expression.
Identifiers which are strings can also have an index along with them in square brackets as part of the string.
Parameters:
| Name |
Type |
Argument |
Description |
identifier |
string
|
|
index, name, id |
domRelation |
accessor
|
<optional>
|
_in, _near or any other DOM relation API |
Returns:
A handle to html element
-
_timebox(identifier) → {Node}
-
Returns an accesor for form element of type time
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_title()
-
Returns the title of page defined in title tags
Returns:
Title of page
-
_type(element, text)
-
Types the text into the element. Different from _setValue. _type does not bring or remove focus from element.
Parameters:
| Name |
Type |
Description |
element |
element
|
HTML element in which the text is to be typed |
text |
string
|
The text to be typed |
-
_uncheck(checkBoxOrRadioElement)
-
Unchecks the given checkbox or radio element. If already checked, this API does not do anything.
Parameters:
| Name |
Type |
Description |
checkBoxOrRadioElement |
element
|
The check box or Radio element to check |
-
_under(accessor)
-
_under is a DOM relation marker which specifies that the element should be searched under another element.
Parameters:
| Name |
Type |
Description |
accessor |
accessor
|
Accessor for the element to be set as anchor point or refernece point |
Returns:
A handle to the reference point
-
_unmaskLogs(endMsg)
-
Toggles _maskLogs(). Re-enables normal report logging. $endMsg is visible in logs.
Parameters:
| Name |
Type |
Description |
endMsg |
string
|
Message displayed in logs |
-
_urlbox(identifier) → {Node}
-
Returns an accesor for form element of type="url"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_userDataDir()
-
Returns absolute path to userdata directory, given a relative path.
-
_userDataPath()
-
Returns the path to userdata.
-
_verifyLayout(string, pixel)
-
_verifyLayout internally checks if the 2 elements are in same row or line. if the difference of the y co-ordinate of the 1st and 2nd element is less than or equal to 4. Sahi will consider both of the elements are in same row or line
Parameters:
| Name |
Type |
Description |
string |
string
|
String which is returned by _readLayoutFile(text_file_path) |
pixel |
int
|
pixel value that need to ignore while validating the page layout |
Examples
//Reads the data which is stored in the variable by using _readLayoutFile(text_file_path) and validate the page layout
var $data = _readLayoutFile("layout.txt");
_verifyLayout($data, 4);
$threshold = 4;
-
_wait(maxTime, condition)
-
Waits for a particular time interval or a condition to be true
Parameters:
| Name |
Type |
Argument |
Description |
maxTime |
integer
|
|
Time in milliseconds after which the execution will resume |
condition |
boolean
|
<optional>
|
Condition which when satisfied will resume the execution |
Example
//Will stop execution for a second
_wait(1000);
//Will wait Will wait till div by id "ajaxy" is populated or one second, whichever occurs sooner
_wait(1000, _byId("ajaxy").innerHTML!="");
-
_weekbox(identifier) → {Node}
-
Returns an accesor for form element of type="week"
Parameters:
| Name |
Type |
Description |
identifier |
identifier
|
Index, Id or name |
Returns:
-
Type
-
Node
-
_windowAction(action)
-
Performs different actions on browser windows.Allowed actions are
- focus
- maximize
- minimize
- restore
- refresh
Parameters:
| Name |
Type |
Description |
action |
string
|
The action to be performed |
Example
//maximize the browser window
_windowAction("maximize");
-
_writeCSVFile(array2d, filePath, overwrite, wordSeparator)
-
Writes a 2 dimensional array into a file in CSV format, using the given wordSeparator (default is comma)
Parameters:
| Name |
Type |
Description |
array2d |
array
|
two dimensional array to write into csv |
filePath |
string
|
path where file is to be saved |
overwrite |
boolean
|
set true to overwrite previous file with same name |
wordSeparator |
string
|
default is comma |
-
_writeFile(text, filePath, overwrite)
-
Writes the text into file at filePath. if overwrite is true, the file contents are overwritten. Default is false which will append text at the end.
Parameters:
| Name |
Type |
Argument |
Description |
text |
string
|
|
The text to write in the file |
filePath |
string
|
|
path of the file |
overwrite |
boolean
|
<optional>
|
set to true if existing file is to be averwritten |
-
_writeToFile(text, filePath, overwrite)
-
Same as _writeFile. Writes the text into file at filePath. if overwrite is true, the file contents are overwritten. Default is false which will append text at the end.
Parameters:
| Name |
Type |
Argument |
Description |
text |
string
|
|
The text to write in the file |
filePath |
string
|
|
path of the file |
overwrite |
boolean
|
<optional>
|
set to true if existing file is to be averwritten |
-
_xy(element, x, y)
-
Specifies the coordinates on element where the event is fired. Negative values can be given to specify offset from right and bottom.
Parameters:
| Name |
Type |
Description |
element |
element
|
element where event is to be fired |
x |
integer
|
value in pixels from left |
y |
integer
|
value in pixels from top |
Examples
//clicks inside the button, 10px from the left and 20 pixels from the top.
_click(_xy(_button("id"), 10, 20))
// clicks inside the button, 5px from the right and 10px from the bottom.
_click(_xy(_button("id"), -5, -10))


Welcome to Monica's Icebreaker Webpage
Places I Have Lived
- Vancouver, Canada - I was born here!
- Seoul, South Korea
- North York - Toronto, Canada
- Milton - GTA, Canada
Interests & Hobbies
- Cute Characters: Rilakkuma, Cinnamoroll, Little Twin Stars
- Typography & Graphic Design
- Travelling: I want to go to Greece, Spain, and Japan!
- Cooking & Baking: Sushi, Udon, Macarons
- Exercising: Hot Yoga, Hiking
Education
Bachelor of Honor's Mathematics (Co-Op), Math and Business
Work Experience
Analyst, TJX Canada