PhantomJS - Headless browser
CasperJS - Javascript Testing Framework
A headless WebKit browser that is scriptable with Javascript API.
It has native support for most important web standards like DOM handling, CSS selector, JSON, Canvas and SVG.
$ npm install -g phantomjs
console.log('Loading a web page');
var page = require('webpage').create();
var url = 'http://www.phantomjs.org/';
page.open(url, function (status) {
//Page is loaded!
phantom.exit();
});
$ phantomjs myTest.js
var webPage = require('webpage');
var page = webPage.create();
page.open('https://is-mebox-vm/synygate/?envId=575', function(status) {
var title = page.evaluate(function() {
return document.title;
});
console.log(title);
phantom.exit();
});
Can be easily integrated with Selenium via GhostDriver
if (browserName.equalsIgnoreCase("phantomjs")) {
DesiredCapabilities caps = DesiredCapabilities.phantomjs();
caps.setJavascriptEnabled(true);
String[] phantomArgs = new String[]{ "--webdriver-loglevel=NONE",
"--web-security=no", "--ignore-ssl-errors=yes" };
caps.setCapability(PhantomJSDriverService.PHANTOMJS_CLI_ARGS, phantomArgs);
caps.setCapability("takesScreenshot", true);
caps.setCapability("phantomjs.page.settings.userAgent",
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:24.0) Gecko/20100101 Firefox/28.0");
return new PhantomJSDriver(caps);
* without Selenium Grid
Selenium Grid Infrastructure
Running scripts directly with PhantomJS
navigation scripting & testing utility
casper.test.begin('TestSuite', numberOfTests, function suite(test) {
casper.start(url, function () {
console.log('Title: ' + this.getTitle());
console.log('Url: ' + this.getCurrentUrl());
test.assertTitle("Optymyze", "Application title is the one expected");
test.assertVisible('input[name=username]', 'Login field is visible');
test.assertVisible('input[name=password]', 'Password field is visible');
this.sendKeys('input[name=username]', 'user');
this.sendKeys('input[name=password]', 'password');
test.assertExists('button', 'Login button exists');
this.click('button');
});
casper.then(function(){
test.assertVisible('div[component=UIFeatureDropDownList]', 'Product DropDown menu is visible');
});
casper.run(function () {
test.done();
});
casper.viewport(1360, 768);
casper.on('step.error', function(err) {
this.capture(err.message + '.png');
});
});
$ casperjs test myTest.js