- Explore
Introduction, screen-shots, features, limitations
- Getting started
Prerequisites, download, install, browser configuration, record, playback, view logs
- Sahi Scripting Basics - I
Statements, variables, functions, conditions and looping, _include
- Sahi Scripting Basics - II
- Sahi APIs (built-in functions)
- All APIs
- Browser Accessor APIs
- Browser Action APIs
- Miscellaneous APIs
- Sahi Scripting - Calling Java
- Exception handling using try-catch
- Recovering without try-catch using _setRecovery
- Script lifecycle call back functions
onScriptFailure, onScriptError, onScriptEnd
- Data Driven Testing
_getDB, CSV Files, Excel, Databases
- Multithreaded Playback (Parallel execution)
suites, commandline, ant
- Advanced techniques, tips and examples
- HTTPS/SSL Sites
- Configuring an External proxy
- Adding jars to Sahi's classpath
- Configuring Browser Types
- Sahi headless with PhantomJS
- Sahi headless with Xvfb
- Sahi with Android
- Tweaking Sahi APIs
- Jenkins Integration
- Other language drivers
Driving Sahi from Java, Ruby etc.
- Java
- Ruby
- Trouble Shooting Sahi
- Sahi Pro
- Documentation (PDF)
- Excel Framework
- Load Testing (Beta)
- Sahi Flex Support - sfl (Beta)
- Running tests on multiple machines
Sahi scripts run on the Rhino javascript engine. This allows Sahi to call any Java code in the classpath of Sahi.
Calling Java code only requires prepending the full package name with “Packages.”
Below is a simple example to print on the console.
function printThroughJava(s){
Packages.java.lang.System.out.println("Through Java: " + s);
}
printThroughJava("Hi there");
// Should print "Through Java: Hi there" on the console.
Another thing to note is that Javascript does not have types, so variable types are declared with just var.
For example:
function printThroughJava(s){
var sysout = Packages.java.lang.System.out;
// sysout would have been of type java.io.PrintStream in java.
// but here declared with only var
sysout.println("Through Java: " + s);
}
This is how _readFile is implemented in Sahi:
// Part of lib.js
// Note: ""+ is used to convert Java string to Javascript string
Sahi.prototype._readFile = function (filePath) {
return "" + Packages.net.sf.sahi.util.Utils.readFileAsString(filePath);
};