| Share
  1. Explore
    Introduction, screen-shots, features, limitations
  2. Getting started
    Prerequisites, download, install, browser configuration, record, playback, view logs
  3. Sahi Scripting Basics - I
    Statements, variables, functions, conditions and looping, _include
  4. Sahi Scripting Basics - II
  5. Sahi APIs (built-in functions)
    1. Browser Accessor APIs
    2. Browser Action APIs
    3. Miscellaneous APIs
  6. Sahi Scripting - Calling Java
  7. Exception handling using try-catch
  8. Recovering without try-catch using _setRecovery
  9. Data Driven Testing
    _getDB, CSV Files, Excel, Databases
  10. Multithreaded Playback (Parallel execution)
    suites, commandline, ant
  11. Advanced techniques, tips and examples
    1. HTTPS/SSL Sites
    2. Configuring an External proxy
    3. Adding jars to Sahi's classpath
  12. Other language drivers Driving Sahi from Java, Ruby etc.
    1. Java
    2. Ruby

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




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
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.


  • 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.
Details
API _writeToFile(text, filePath[, overwrite])
Notes Same as _writeFile
API _readCSVFile(filePath)
Notes Reads a csv file and returns a 2 dimensional array of the contents. Details
API _writeCSVFile(filePath)
Notes Writes a 2 dimensional array into a file in CSV format.
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.



---