Created
April 29, 2016 18:37
-
-
Save kob-aha/0ed4b41c1cbecf9e8fa293363872c666 to your computer and use it in GitHub Desktop.
CasperJS sample file for connecting to gmail and capturing main page
This file contains 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
var casper = require('casper').create(); | |
var system = require('system'); | |
var username = [ENTER_EMAIL_HERE]; | |
var userpass = [ENTER_PASSWORD_HERE]; | |
function enterUsername(username) { | |
document.getElementById("Email").value=username; | |
document.getElementById("next").click(); | |
} | |
function enterPassword(password){ | |
document.getElementById("Passwd").value=password; | |
document.getElementById("signIn").click(); | |
} | |
function enterDigits(digits) { | |
document.getElementById("idvPreregisteredPhonePin").value=digits; | |
document.getElementById("submit").click(); | |
} | |
casper.start().thenOpen('http://mail.google.com/'); | |
casper.then(function() { | |
this.evaluate(enterUsername, username); | |
}); | |
casper.waitForSelector('input#Passwd', function(){ | |
this.evaluate(enterPassword, userpass); | |
}, | |
function(){ | |
console.log('Got timeout waiting for password'); | |
this.capture('/tmp/passwordTimeout.png'); | |
}, 15000); | |
casper.waitForSelector('input#idvPreregisteredPhonePin', function() { | |
this.echo('enter 6 digit code:'); | |
var digits = system.stdin.readLine(); | |
this.evaluate(enterDigits, digits); | |
}, | |
function(){ | |
console.log('Got timeout waiting for digit code'); | |
this.capture('/tmp/digitsTimeout.png'); | |
}, 10000); | |
casper.waitForSelector('div.TK', function() { | |
this.echo('finished connecting to gmail'); | |
this.capture('/tmp/finishedLogin.png'); | |
}, | |
function(){ | |
this.capture('/tmp/loadingTimeout.png'); | |
console.log('Got timeout waiting for digits input'); | |
}, 20000); | |
casper.run(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment