$ brew update
$ brew install casperjs --devel
To test if the installation of casperjs was successful, type on terminal
$ which casperjs
you should get - /usr/local/bin/casperjs which means everything is fine
2. Install PhantomJS : open the terminal and fire up these commands
$ brew install node
This will install node. After which you can use the node/npm without using sudo
$ npm install -g phantomjs
To test if the installation of phantoms was successful, type on terminal
$ which phantomjs
you should get - /usr/local/bin/phantomjs which means everything is fine
Now you are all set to write your first test. Make sure you have BBEDIT installed ( best Code editor , i have seen ). Here, is a sample first test script for you
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
phantom.casperTest = true; | |
var casper = require('casper').create({ | |
verbose: false, | |
logLevel: 'debug', | |
pageSettings: { | |
loadImages: false, // The WebPage instance used by Casper will | |
loadPlugins: false, // use these settings | |
} | |
}); | |
var x = require('casper').selectXPath; | |
casper.options.viewportSize = {width: 1271, height: 652}; | |
casper.on('page.error', function(msg, trace) { | |
this.echo('Error: ' + msg, 'ERROR'); | |
for(var i=0; i<trace.length; i++) { | |
var step = trace[i]; | |
this.echo(' ' + step.file + ' (line ' + step.line + ')', 'ERROR'); | |
} | |
}); | |
casper.test.begin('Casper Test for all Controls', function(test) { | |
casper.start('http://vinayjagtap.com/testautomation/'); | |
casper.waitForSelector("form input[name='g1200-name']", | |
function success() { | |
test.assertExists("form input[name='g1200-name']"); | |
this.click("form input[name='g1200-name']"); | |
}, | |
function fail() { | |
test.assertExists("form input[name='g1200-name']"); | |
}); | |
casper.waitForSelector("form input[name='g1200-name']", | |
function success() { | |
test.assertExists("form input[name='g1200-name']"); | |
this.click("form input[name='g1200-name']"); | |
}, | |
function fail() { | |
test.assertExists("form input[name='g1200-name']"); | |
}); | |
casper.waitForSelector("input[name='g1200-name']", | |
function success() { | |
this.sendKeys("input[name='g1200-name']", "Vinay"); | |
}, | |
function fail() { | |
test.assertExists("input[name='g1200-name']"); | |
}); | |
casper.waitForSelector("input[name='g1200-email']", | |
function success() { | |
this.sendKeys("input[name='g1200-email']", "vinay@testr.com"); | |
}, | |
function fail() { | |
test.assertExists("input[name='g1200-email']"); | |
}); | |
casper.waitForSelector("form input[name='g1200-website']", | |
function success() { | |
test.assertExists("form input[name='g1200-website']"); | |
this.click("form input[name='g1200-website']"); | |
}, | |
function fail() { | |
test.assertExists("form input[name='g1200-website']"); | |
}); | |
casper.waitForSelector("input[name='g1200-website']", | |
function success() { | |
this.sendKeys("input[name='g1200-website']", "vinayjag.com"); | |
}, | |
function fail() { | |
test.assertExists("input[name='g1200-website']"); | |
}); | |
casper.waitForSelector("#g1200-dropdown", | |
function success() { | |
test.assertExists("#g1200-dropdown"); | |
this.click("#g1200-dropdown"); | |
}, | |
function fail() { | |
test.assertExists("#g1200-dropdown"); | |
}); | |
casper.waitForSelector("form input[name='g1200-checkbox']", | |
function success() { | |
test.assertExists("form input[name='g1200-checkbox']"); | |
this.click("form input[name='g1200-checkbox']"); | |
}, | |
function fail() { | |
test.assertExists("form input[name='g1200-checkbox']"); | |
}); | |
casper.waitForSelector("form input[name='g1200-newfield']", | |
function success() { | |
test.assertExists("form input[name='g1200-newfield']"); | |
this.click("form input[name='g1200-newfield']"); | |
}, | |
function fail() { | |
test.assertExists("form input[name='g1200-newfield']"); | |
}); | |
casper.waitForSelector("form input[type=submit][value='Submit »']", | |
function success() { | |
test.assertExists("form input[type=submit][value='Submit »']"); | |
this.click("form input[type=submit][value='Submit »']"); | |
this.capture('screen.png'); | |
}, | |
function fail() { | |
test.assertExists("form input[type=submit][value='Submit »']"); | |
this.capture('screen.png'); | |
}); | |
/* submit form */ | |
casper.run(function() {test.done();}); | |
}); |
Remember to run this command in terminal, this will take care of your blank screenshots and https:// requests if any
$ casperjs --ignore-ssl-errors=yes --ssl-protocol=any caspertest.js