Top Rounds
| We are Hiring! |

Miscellaneous APIs ·

Functions available on browser and on proxy

API _random(limit)
Notes Returns a random number between 0 and limit. Details
API _scriptName()
Notes Returns the name of the current script
API _scriptPath()
Notes Returns the path of the current script
API _popup(identifier)
Identifier windowName, windowTitle
Notes Returns a handle to the window. The identifier can be a regular expression.
_popup() is used as a prefix to statements which need to be executed on another window.

Eg. _popup("popWin")._click(_link("Click me")); _popup(/popWin.*/)._click(_link("Click me")); _popup("Window Title")._click(_link("Click me"));
API _selectWindow(popupId)
popupId windowName, windowTitle; if left blank, it chooses the base window
Notes 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.

Eg. _selectWindow("popWin"); // select 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;
API _sessionInfo()
Notes Returns information of the current session. The object has attribures: isRecording isPlaying isPaused sessionId
API _suiteInfo()
Notes Returns information of the current session. The object has attribures: suitePath: Path of suite base: Base url for suite browser: Browser executable path sessionId: SessionId of suite browserOption: browserOption passed to Suite browserProcessName: browserProcessName passed to Suite suiteName: name of suite
API _userDataDir()
Notes Returns the path to userdata.
API _lastDownloadedFileName()
Notes Returns the name of the last downloaded file name. Details
API _setStrictVisibilityCheck(boolean)
Notes _setStrictVisibilityCheck(true); makes Sahi ignore elements which are not visible.
_setStrictVisibilityCheck(false) makes sahi revert to original behavior of considering all elements in the DOM.
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




Functions available on browser only

API _savedRandom(key)
Notes Deprecated
Returns a previously saved random number agains that key. Details
Related _resetSavedRandom
API _getGlobal(key)
Notes Returns value stored against key. Details
Related _setGlobal




Functions available on proxy only

API _logException(exception)
Notes Logs an exception. Used in catch block of try-catch. Details
API _logExceptionAsFailure(exception)
Notes Logs an exception and stops execution. Used in catch block of try-catch. Details
API _stopOnError()
Notes Makes the script stop if an error occurs. This is the default behavior.
API _continueOnError()
Notes Makes script continue inspite of errors. Can be turned off with _stopOnError()
API _setRecovery(fn)
Notes 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(). Details
API _removeRecovery(fn)
Notes Removes any recovery function which was set via _setRecovery. Details


  • Working with database
API _getDB(driver, jdbcurl, username, password)
Notes Returns a DB object which can be used to query the database. Details


  • Working with files
API _readFile(filePath)
Notes Reads a file at filePath and returns its contents as a string. Details
API _writeFile(text, filePath[, overwrite])
Notes 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.
API _writeToFile(text, filePath[, overwrite])
Notes Same as _writeFile
API _readCSVFile(filePath, wordSeparator)
Notes 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.
API _writeCSVFile(array2d, filePath, overwrite, wordSeparator)
Notes Writes a 2 dimensional array into a file in CSV format, using the given wordSeparator (default is comma)
API _deleteFile(filePath)
Notes Deletes the file at filePath.
API _renameFile(oldFilePath, newFilePath)
Notes Renames (or moves) a given file from oldFilePath to newFilePath. If newFilePath already exists, it will be overwritten


  • Data driven testing
API _dataDrive(fn, data2DArray)
Notes Loops over data2DArray, and invokes function fn with each row of data. The invocation is within a try catch block with exception logging. More on data driven testing


  • Unit testing
API _runUnitTests()
Notes _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.


  • Reading URL content
API_readURL(url)
NotesReads the content at the specified URL and returns its contents as a string


  • APIs for browser detection
API_isIE(), _isIE9()
NotesReturns true if browser is Internet Explorer
API_isFF(), _isFF2(), _isFF3(), _isFF4()
NotesReturns true if browser is Mozilla Firefox
API_isChrome()
NotesReturns true if browser is Google Chrome
API_isSafari()
NotesReturns true if browser is Safari



---


Top Rounds