Last active
December 19, 2015 12:49
-
-
Save pcon/5957894 to your computer and use it in GitHub Desktop.
CasperJs logging into Salesforce
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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