var casper = require('casper').create();
casper.start('http://google.fr/', function() {
});
casper.then(function() {
});
casper.thenClick('link', function() {
});
casper.then().repeat(2, function() {
});
casper.back(function() {
});
casper.run(function() {
});
casper.start('http://domain.tld/page.html', function() {
this.test.assertExists('#logo', 'The logo exists');
});
casper.then(function() {
this.click('.geoEntity.restaurant a');
});
casper.then(function() {
this.clickLabel('Fermer la fenêtre');
});
var x = require('casper').selectXPath;
casper.thenOpen('http://domain.tld/page.html', function() {
this.click(x('//*[@id="logo"]'));
});
<form action="/contact" id="contact-form" enctype="multipart/form-data">
<input type="text" name="subject">
<input type="radio" name="civility" value="Mr"/> Mr
<input type="radio" name="civility" value="Mme"/> Mme
<input type="text" name="name"/>
<input type="email" name="email"/>
<input type="file" name="attachment"/>
<input type="checkbox" name="cc"/> Copie carbone
<input type="submit"/>
</form>
casper.start('http://some.tld/contact.form', function() {
this.fill('form#contact-form', {
'subject': 'Réclamation',
'civility': 'Mr',
'name': 'Chuck Norris',
'email': '[email protected]',
'cc': true,
'attachment': '/Users/chuck/i-am-not-happy.doc'
}, true);
});
casper.waitForSelector('.tweet-row', function() {});
casper.waitWhileSelector('.selector', function() {});
casper.waitUntilVisible('.tweet-row', function() {});
casper.waitWhileVisible('.selector', function() {});
casper.waitForPopup(/popup\.html$/, function() {});
casper.waitForResource("foobar.png"), function() {});
casper.waitFor(function check() {
...
}, function then() {
...
}, function timeout() {
...
});
casper.waitFor(function check() {
return this.evaluate(function(zoom) {
return $('.slider-handler').css('bottom') === zoom;
}, {'zoom': '50%'});
});
casper.start('http://www.google.fr/', function() {
this.test.assertEval(function() {
return document.querySelectorAll('form').length > 0;
}, 'google.fr has at least one form');
this.test.assertEval(function() {
return document.title === title;
}, 'google.fr title is "Google"', 'Google');
});
casper.start().thenOpen('http://google.com', function() {
this.capture('google.png');
});
casper.start('http://www.weather.com/', function() {
this.captureSelector('weather.png', '#wx-main');
});
casper.test.on("fail", function(failure) { // Capture en cas d’erreur
var fileName = failure.file.split("/"); // Fichier de test
fileName = fileName[fileName.length-1].split('.')[0]; // Sans l’extension
this.capture('fail-' + failure.type + '-' + fileName);
});
this.download('http://www.google.com', 'google_homepage.html');
casper = require('casper').create {
clientScripts: ["includes/underscore-min.js"]
remoteScripts: ["http://code.jquery.com/jquery-1.9.1.min.js"]
}
casper.on('open', function(location, settings) {
casper.echo(location);
});
// listening to a custom event
casper.on('google.loaded', function() {
this.echo('Google page title is ' + this.getTitle());
});
casper.start('http://google.com/', function() {
// emitting a custom event
this.emit('google.loaded');
});
casper.setFilter('open.location', function(location) {
return /\?+/.test(location) ? location += "&foo=42" : location += "?foo=42";
});
var casper = require('casper').create({
verbose: true,
logLevel: "debug"
});
/
#