Skip to content

Instantly share code, notes, and snippets.

@mickaelandrieu
Last active December 15, 2015 11:28
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 mickaelandrieu/5252776 to your computer and use it in GitHub Desktop.
Save mickaelandrieu/5252776 to your computer and use it in GitHub Desktop.
Sample of command that does'nt work (casperjs includes)
casperjs --includes=utilities/login.js test@test.com password domain test bank.js
Unable to open file: test@test.com
var casper = require('casper').create({
/* more traces with this 2 following options */
verbose: true,
//logLevel: "info",
httpStatusHandlers: {
500: function(self, resource) {
this.warn("Resource at " + resource.url + " server error (500)");
},
404: function(self, resource) {
this.warn("Resource at " + resource.url + " is unreachable (404)");
},
301: function(self, resource) {
this.warn("Resource at " + resource.url + " is moved permanently (301)");
},
302: function(self, resource) {
this.warn("Resource at " + resource.url + " is moved temporarily (302)");
}
},
});
/* get args */
var email = casper.cli.get(0);
var password = casper.cli.get(1);
var domain = casper.cli.get(2);
// Go to the AM 2 Login Page
casper.test.comment('Go to Login Page');
casper.start(domain, function() {
this.test.pass('Login Page is loaded');
this.capture(folder+'pageLoad.png');
});
// Test a Bad submit
casper.thenOpen(domain,function() {
this.test.info('Current location is ' + this.getCurrentUrl());
this.fill('#showcaseLoginForm', {
'_username': email,
'_password': password
}, true);
});
// Test a Bad submit
casper.then(function() {
this.test.info('Current location is ' + this.getCurrentUrl());
});
casper.run(function() {
this.test.done();
});
@n1k0
Copy link

n1k0 commented Mar 27, 2013

try it that way:

casperjs test --includes=utilities/login.js bank.js --email=test@test.com --password=password --domain=domain

and:

var email = casper.cli.get('email');
var password = casper.cli.get('password');
var domain = casper.cli.get('domain');

Also, be sure to use the casperjs testsubcommand, and don't create a casper instance within that environment.

@mickaelandrieu
Copy link
Author

Works ! Thanks, I update my sample (maybe I can do a PR for the documentation ?)

@n1k0
Copy link

n1k0 commented Mar 27, 2013

It's theoretically documented already, but feel free to send a PR with enhancements if you think the docs need them :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment