Plugin supports the execution of native PhantomJS or CasperJS scripts. This plugin can be useful in the writing functional tests suites of a website or simple integrations via a web interface. It embeds CasperJs 1.1.1b3
- Deployit requirements
- Deployit: version 4.0.+
Place the plugin JAR file into your SERVER_HOME/plugins
directory.
Define a casperjs.Runtime
container under the desired overthere.Host
. The host will be used to stage the PhantomJS runtime and execute the script. The executable
property must be set to one of the following depending on the host platform :
- windows: win/phantomjs.exe
- osx: osx/phantomjs
- linux 64-bit: linux_64/phantomjs
- linux 32-bit: linux_32/phantomjs
If your platform is not supported, you will have to compile PhantomJS for your platform. Please refer to PhantomJS build instructions for details. Place your custom compiled executable in <DEPLOYIT_SERVER_HOME>/ext/phantomjs/runtime/<platform name>
.
Define casperjs.ScriptSpec
or casperjs.Script
deployable items in a package. These deployables are targeted to casperjs.Runtime
containers in an environment.
All properties of a deployed can be accessed directly in the script by referring to the deployed
javascript variable.
Please refer to PhantomJS and CasperJS sites for detailed documentation on how to write scripts that will run in the headless PhantomJS Webkit.
When running CasperJS test scripts, the isCasperJSTest
property must be set to true
.
Following sample is from the CasperJS Testing documentation
casper.test.begin('Google search retrieves 10 or more results', 5, function suite(test) {
casper.start("http://www.google.fr/", function() {
test.assertTitle("Google", "google homepage title is the one expected");
test.assertExists('form[action="/search"]', "main form is found");
this.fill('form[action="/search"]', {
q: "casperjs"
}, true);
});
casper.then(function() {
test.assertTitle("casperjs - Recherche Google", "google title is ok");
test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
test.assertEval(function() {
return __utils__.findAll("h3.r").length >= 10;
}, "google search for \"casperjs\" retrieves 10 or more results");
});
casper.run(function() {
test.done();
});
});
casper.test.begin('Custom search engine retrieve 10 or more results', 5, function suite(test) {
casper.start("http://"+deployed.container.host.address+":8080/index.html", function() {
this.echo("URL is: http://"+deployed.container.host.address+":8080/index.html" , 'INFO');
test.assertTitle("Google", "google homepage title is the one expected");
test.assertExists('form[action="/search"]', "main form is found");
this.fill('form[action="/search"]', {
q: "casperjs"
}, true);
});
casper.then(function() {
test.assertTitle("casperjs - Recherche Google", "google title is ok");
test.assertUrlMatch(/q=casperjs/, "search term has been submitted");
test.assertEval(function() {
return __utils__.findAll("h3.r").length >= 10;
}, "google search for \"casperjs\" retrieves 10 or more results");
});
casper.run(function() {
test.done();
});
});