Sahi Pro - Sahi headless execution with PhantomJS
PhantomJS is a headless browser based on WebKit. (A headless browser runs without a user interface)Documentation since Sahi Pro V4.3.2
- Download phantomjs-1.x.x-win32-dynamic.zip from http://code.google.com/p/phantomjs/downloads/list (Or choose the correct one from http://phantomjs.org/download.html)
- Unzip it and copy phantomjs.exe to sahi/ext/phantomjs folder such that you have sahi/ext/phantomjs/phantomjs.exe (for linux copy phantomjs file)
- Click "Configure" link on Dashboard, and, if not present, add For Windows:
- Save and restart Sahi.
- To run a test in PhantomJS: Click on "Bin" on the dashboard (or navigate to sahi/userdata/bin on a command prompt) and run the command
<browserType>
<name>phantomjs</name>
<displayName>PhantomJS</displayName>
<icon>phantomjs.png</icon>
<path>$sahiDir\ext\phantomjs\phantomjs.exe</path>
<options>--proxy=localhost:9999 $sahiDir\ext\phantomjs\sahi.js</options>
<processName>phantomjs.exe</processName>
<capacity>100</capacity>
<useSystemProxy>false</useSystemProxy>
</browserType>
For Linux<browserType>
<name>phantomjs</name>
<displayName>PhantomJS</displayName>
<icon>phantomjs.png</icon>
<path>$sahiDir/ext/phantomjs/phantomjs</path>
<options>--proxy=localhost:9999 $sahiDir/ext/phantomjs/sahi.js</options>
<processName>phantomjs</processName>
<capacity>100</capacity>
<useSystemProxy>false</useSystemProxy>
</browserType>
testrunner.bat demo/sahi_demo.sah http://sahi.co.in/demo/ phantomjs
This will run the Sahi script without opening a browser.
Older Documentation (before Sahi Pro V4.3.2)
- Download phantomjs-1.x.x-win32-dynamic.zip from http://code.google.com/p/phantomjs/downloads/list.google.com/p/phantomjs/downloads/list
- Unzip it to, say C:\phantomjs-1.x.x-win32 such that phantomjs.exe is available at
C:\phantomjs-1.x.x-win32\phantomjs.exe - Create a file sahi.js in C:\phantomjs-1.x.x-win32 with the content below: For version 1.2.0 onwards, use:
- Click "Configure" link on Dashboard, and add
- Save and restart Sahi.
- To run a test in PhantomJS: Click on "Bin" on the dashboard (or navigate to sahi/userdata/bin on a command prompt) and run the command
if (phantom.args.length === 0) {
console.log('Usage: sahi.js <Sahi Playback Start URL>');
phantom.exit();
} else {
// var address = unescape(phantom.args[0]); // use if < v1.7
var address = phantom.args[0];
console.log('Loading ' + address);
var page = new WebPage();
page.open(address, function(status) {
if (status === 'success') {
var title = page.evaluate(function() {
return document.title;
});
console.log('Page title is ' + title);
} else {
console.log('FAIL to load the address');
}
});
}
For version 1.1.0, use:if (phantom.state.length === 0) {
if (phantom.args.length === 0) {
console.log('Usage: sahi.js <Sahi Playback Start URL>');
phantom.exit();
} else {
var address = unescape(phantom.args[0]);
phantom.state = "sahi script running";
console.log('Loading ' + address);
phantom.open(address);
}
} else {
if (phantom.loadStatus == 'success') {
console.log('Page title is ' + document.title);
} else {
console.log('FAIL to load the address');
}
}
The above code is based on the example provided by PhantomJS<browserType>
<name>phantomjs</name>
<displayName>PhantomJS</displayName>
<icon>phantomjs.png</icon>
<path>C:\phantomjs-1.1.0-win32\phantomjs.exe</path>
<options>--proxy=localhost:9999 C:\phantomjs-1.1.0-win32\sahi.js
</options>
<processName>phantomjs.exe</processName>
<capacity>100</capacity>
<force>true</force>
</browserType>
before the ending
tag in browser_types.xmltestrunner.bat demo/sahi_demo.sah http://sahi.co.in/demo/ phantomjs
This will run the Sahi script without opening a browser.