Skip to content

Instantly share code, notes, and snippets.

@caingougou
Created February 20, 2013 08:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caingougou/4994088 to your computer and use it in GitHub Desktop.
Save caingougou/4994088 to your computer and use it in GitHub Desktop.
casper sample
var casper = require('casper').create({
verbose: true,
logLevel: "debug",
pageSettings: {
localToRemoteUrlAccessEnabled : true
}
});
// casper.on('load.finished', function() {
// this.log('Page loaded', 'debug');
// });
casper.on('resource.requested', function(resource) {
this.log('GET:' + resource.url, 'debug');
});
// casper.on('resource.received', function(resource) {
// this.log('Load "' + resource.url + '" done.', 'debug');
// });
casper.start();
casper.viewport(1024, 768);
casper.userAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X)');
casper.thenOpen('http://ep/', function() {
this.log("Load Page Done", 'debug');
this.capture('ep.png', {
top : 0,
left : 0,
width : 1024,
height : 768
});
});
casper.wait(10000, function() {
this.log("Wait the page to load", 'debug');
this.evaluate(function() {
document.querySelector('input#login_username').setAttribute('value', '');
document.querySelector('input#login_password').setAttribute('value', '');
});
// var evt = document.createEvent("MouseEvents");
// var el = document.elementFromPoint(600, 750);
// evt.initMouseEvent("click", true, true, window, 1, 0, 0, 800, 400, false, false, false, false, 0, null);
// el.dispatchEvent(evt);
this.capture('ep1.png', {
top : 0,
left : 0,
width : 1024,
height : 768
});
});
casper.wait(10000, function() {
this.capture('ep2.png', {
top : 0,
left : 0,
width : 1024,
height : 768
});
});
casper.then(function() {
this.log('Done', 'debug');
// this.debugHTML();
});
casper.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment