Skip to content

Instantly share code, notes, and snippets.

@theednaffattack
Forked from pcon/sfdclogin.casper.js
Created March 15, 2014 19:17
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 theednaffattack/9572366 to your computer and use it in GitHub Desktop.
Save theednaffattack/9572366 to your computer and use it in GitHub Desktop.
/*jslint browser: true, regexp: true */
/*global casper, require */
var LOGIN_URL, LOGIN_USERNAME, LOGIN_PASSWORD, casp;
casp = require('casper').create({
viewportSize: {
width: 1024,
height: 768
},
verbose: true,
logLevel: 'warning'
});
if (!casp.cli.has('username') && !casp.cli.has('password')) {
casp.echo('Usage: $ casperjs sfdclogin.casper.js --username=USERNAME --password=PASSWORD [--prod]').exit(-1);
}
if (casp.cli.has('prod')) {
LOGIN_URL = 'https://login.salesforce.com/';
} else {
LOGIN_URL = 'https://test.salesforce.com/';
}
LOGIN_USERNAME = casp.cli.get('username');
LOGIN_PASSWORD = casp.cli.get('password');
casp.start(LOGIN_URL, function () {
'use strict';
this.log('Logging in', 'debug');
this.fill('form', {
'username': LOGIN_USERNAME,
'pw': LOGIN_PASSWORD
}, true);
this.log('Logged in', 'debug');
});
casp.then(function () {
'use strict';
this.echo('We\'re logged in. Now we can do more stuff like take a screenshot!');
this.waitForSelector('#userNavLabel', function () {
this.captureSelector('test.png', 'html');
this.log('saved screenshot of ' + this.getCurrentUrl() + 'to test.png', 'warning');
}, function () {
this.die('Timeout reached');
this.exit();
}, 12000);
});
casp.run();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment