Ejemplo n.º 1
0
 .then(function() {
     return waitUntil("google auth button is visible", function() {
         return page.evaluate(function(selector) {
             return document.querySelectorAll(selector).length > 0;
         }, selectors.loginWithGoogleButtonSelector);
     });
 })
Ejemplo n.º 2
0
 .then(function() {
     return waitUntil("the trim posts form appear", function() {
         return page.evaluate(function() {
             return document.querySelector("form[name='trimPosts']") !== null;
         });
     });
 })
Ejemplo n.º 3
0
 .then(function() {
     return waitUntil("the page loads with the trimmed posts", function() {
         return page.evaluate(function() {
             return document.querySelectorAll(".js-post").length == 12;
         });
     });
 })
Ejemplo n.º 4
0
 .then(function() {
     return waitUntil("page is loaded", function() {
         return page.evaluate(function() {
             return typeof $ != 'undefined';
         });
     });
 })
Ejemplo n.º 5
0
 .then(function() {
     return waitUntil("done skipping password recovery", function() {
         return getPageState()
             .then(function(state) {
                 return !state.needSkip;
             });
     });
 })
Ejemplo n.º 6
0
 .then(function() {
     return waitUntil("rss import completes", function() {
         return page.get("content")
         .then(function(content) {
             return content.indexOf("Upload complete") > -1;
         });
     });
 })
Ejemplo n.º 7
0
 .then(function() {
     return waitUntil("the about page loads", function() {
         return page.get("content")
         .then(function(content){
             return content.indexOf("About") > -1;
         });
     });
 });
Ejemplo n.º 8
0
 .then(function() {
     return waitUntil("A subscription feed has been added", function() {
         return getFirstFeed(page)
         .then(function(subscriptionInfo) {
             return subscriptionInfo && subscriptionInfo.count == 1;
         });
     });
 })
Ejemplo n.º 9
0
        .then(function() {

            return waitUntil("upload is complete", function() {
                return page.get("content")
                    .then(function(content) {
                        return content.indexOf("Upload complete") > -1;
                    });
            }, 2000);
        });
Ejemplo n.º 10
0
 .then(function() {
     return waitUntil("done submitting google username", function() {
         return getPageState()
             .then(function(state) {
                 return !state.needLogin;
             });
     }, {
         msTimeout: 2000,
         noTimeoutError: true
     });
 })
Ejemplo n.º 11
0
 .then(function() {
     return waitUntil("done submitting google password", function() {
         return getPageState()
             .then(function(state) {
                 return !state.needPassword;
             });
     }, {
         msTimeout: 2000,
         noTimeoutError: true
     });
 })
Ejemplo n.º 12
0
                        .then(function() {
                            return waitUntil("done allowing google account access", function() {
                                return Q()
                                .then(function() {
                                    return getPageState();
                                })                                    
                                .then(function(state) {

                                    return !state.needAllow;
                                });
                            });
                        })
Ejemplo n.º 13
0
function handleGoogleAuth(page) {

    var googleUsername = config.get("googleTest_username");
    var googlePassword = config.get("googleTest_password");

    assert.notEqual(googleUsername, null, "A config setting was not found for googleTest_username.");
    assert.notEqual(googlePassword, null, "A config setting was not found for googleTest_password.");

    function getPageState() {
        return page.evaluate(function(selectors) {

            var isGooglePage = window.location.toString().indexOf("google.com") > -1;
            
            function hasElement(s) {
                return document.querySelector(s) !== null;
            }

            return {
                url: window.location.toString(),
                hash: window.location.hash.toString(),
                needLogin: isGooglePage && window.location.hash == "#identifier",
                needPassword: isGooglePage && window.location.hash == "#password",
                needSkip: isGooglePage && hasElement(selectors.googleNoThanksButton),
                needAllow: isGooglePage && hasElement(selectors.googleAllowSubmit),
                ready: !isGooglePage && hasElement(selectors.logoutButtonSelector)
            };
        }, selectors)
        .fail(function(err) {
            return {
                needLogin: false,
                needSkip: false,
                needAllow: false,
                ready: false
            };
        });
    }

    return waitUntil("done authenticating", function() {
        return getPageState()
            .then(function(state) {

                if (state.needPassword) {
                    return Q()
                    .then(function() {
                        return page.evaluate(function(selectors, username, password) {
                                document.querySelector(selectors.googleLoginPassword).value = password;
                            }, selectors, googleUsername, googlePassword);
                    })
                    .then(function() {
                        return page.clickElement(selectors.googleLoginSubmit);
                    })
                    .then(function() {
                        return waitUntil("done submitting google password", function() {
                            return getPageState()
                                .then(function(state) {
                                    return !state.needPassword;
                                });
                        }, {
                            msTimeout: 2000,
                            noTimeoutError: true
                        });
                    })
                    .then(function() {
                        return false;
                    });
                } else if (state.needLogin) {
                    return Q()
                    .then(function() {
                        return page.evaluate(function(selectors, username, password) {
                                document.querySelector(selectors.googleLoginEmail).value = username;
                            }, selectors, googleUsername, googlePassword);
                    })
                    .then(function() {
                        return page.clickElement(selectors.googleLoginNext);
                    })
                    .then(function() {
                        return waitUntil("done submitting google username", function() {
                            return getPageState()
                                .then(function(state) {
                                    return !state.needLogin;
                                });
                        }, {
                            msTimeout: 2000,
                            noTimeoutError: true
                        });
                    })
                    .then(function() {
                        return false;
                    });
                } else if (state.needSkip) {
                    return page.clickElement(selectors.googleNoThanksButton)
                        .then(function() {
                            return waitUntil("done skipping password recovery", function() {
                                return getPageState()
                                    .then(function(state) {
                                        return !state.needSkip;
                                    });
                            });
                        })
                        .then(function() {
                            return false;
                        });
                } else if (state.needAllow) {

                        return Q()
                        .then(function() {
                            var deferred = Q.defer();
                            setTimeout(function() { deferred.resolve(); }, 5000);  // TODO UGH
                            return deferred.promise;
                        })
                        .then(function() {
                            return page.clickElement(selectors.googleAllowSubmit);
                        })
                        .then(function() {
                            return waitUntil("done allowing google account access", function() {
                                return Q()
                                .then(function() {
                                    return getPageState();
                                })                                    
                                .then(function(state) {

                                    return !state.needAllow;
                                });
                            });
                        })
                        .then(function() {
                            return false;
                        });
                }

                return state.ready;
            });
    }, {
        msTimeout: 16000
    });
}