javascript - Casperjs google auth popup -


the problem: working on casperjs script log application. application utilizes google auth. trying simulate how user sign in, going site, user first clicks sign in google button opens new tab asking google credentials. have these pieces working... stuck when user submits google auth form expectation sign in tab closes , original window recieves credentials , allows user application. if take screen shot after these events still remain on original login page rather gaining access app. code posted below:

var casper = require('casper').create({     verbose: true,     loglevel: 'debug',     waittimeout: 5000,     useragent: 'mozilla/5.0 (macintosh; intel mac os x 10_7_5) applewebkit/537.4 (khtml, gecko) chrome/22.0.1229.94 safari/537.4' });  casper.capturepath = function(name) {     return this.capture('./captures/' + name) }  casper.on('remote.message', function(msg) {    this.echo('remote message caught: ' + msg); });  casper.on("page.error", function(msg, trace) {     this.echo("page error: " + msg, "error"); });  casper.on('popup.created', function() {     this.echo("url popup created : " + this.getcurrenturl(),"info"); });  casper.on('popup.loaded', function() {     this.echo("url popup loaded : " + this.getcurrenturl(),"info"); });  casper     .start('<url>', function() {                     .then(function() {                 this.clicklabel('sign in google', 'button');             })             .waitforpopup(/accounts\.google/)             .withpopup(/accounts\.google/, function(popup) {                                     .fillselectors('form#gaia_loginform', { '#email': '<username>' }, false)                     .thenclick('input#next')                     .wait(500, function() {                         this.waitforselector('#passwd',                             function success() {                                                                     .echo('success', 'info')                                     .fillselectors('form#gaia_loginform', { 'input[name=passwd]': '<password>' }, false)                                     .capturepath('beforesubmit.png')                                     .thenclick('input#signin')                                     .wait(500, function() {                                         this.capturepath('aftersubmit.png');                                     })                                 },                                 function fail() {                                     this.echo('failure');                                 })                     })             })     })     .then(function() {         this.waitforselector('.dashboard-container',             function success() {                                     .echo('logged in!', 'info')                     .capturepath('in.png')             },             function fail() {                                     .capturepath('failed.png')                     .echo('failed login', 'error');             })     }) .run(); 

when this.waitforselector('.dashboard-container', line script timeout because cannot find selector have told grab... presumably because not logging in user. (also application react application incase thats important)

i have been spinning wheels on 1 awhile, insight appreciated!

i think works now. problem was, tried this.waitforselector('.dashboard-container', outside of popup, on main page.

var casper = require('casper').create({     verbose: true,     loglevel: 'debug',     waittimeout: 5000,     useragent: 'mozilla/5.0 (macintosh; intel mac os x 10_7_5) applewebkit/537.4 (khtml, gecko) chrome/22.0.1229.94 safari/537.4',     viewportsize:{width: 1600, height: 900} }); casper.capturepath = function(name) {     return this.capture('./captures/' + name) }  casper.on('remote.message', function(msg) {    this.echo('remote message caught: ' + msg); });  casper.on("page.error", function(msg, trace) {     this.echo("page error: " + msg, "error"); });  casper.on('popup.created', function(newpage) { this.echo("url popup created : " + this.getcurrenturl(),"info"); newpage.viewportsize={width:1600,height:900} });  casper.on('error', function(msg) { this.echo('error: ' + msg,"error"); });// have missed callback!  casper.on('popup.loaded', function() {     this.echo("url popup loaded : " + this.getcurrenturl(),"info"); });  casper     .start('http://domu-test-2/node/10', function() {                     .wait(0,function() {// 'then(function' won't work expected in callback function.                 this.clicklabel('sign in google', 'button');             })             .waitforpopup(/accounts\.google/)             .withpopup(/accounts\.google/, function(popup) {                                      .fillselectors('form#gaia_loginform', { '#email': 'luxadm1' }, false)                     .thenclick('input#next')                     .wait(700, function() {                         this.waitforselector('#passwd',                             function success() {                                                                     .echo('success', 'info')                                     .fillselectors('form#gaia_loginform', { 'input[name=passwd]': '<pass_here>' }, false)                                     .capturepath('beforesubmit.png')                                     .thenclick('input#signin')                                     .wait(300, function() {// less previous '.wait(700, function() {' -- otherwise buggy                                         this.capturepath('aftersubmit.png');                                     })                                 },                                 function fail() {                                     this.echo('failure');                                 })                     })             })     })     .then(function(){//here outside of popup!!         this.withpopup(/accounts\.google/, function(popup){// need here until previous '.withpopup' function switch 'about:blank', otherwise error: 'caspererror: couldn't find popup url matching pattern'                /*.wait(3000,*/ .waitforselector('div.spxs6d',//'.dashboard-container' -- i've not seen such selector there               function success() {                                     .echo('logged in!', 'info')                     .capturepath('in.png')             },             function fail() {                                     .capturepath('failed.png')                     .echo('failed login', 'error');             })     });}) .run(); 

Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -