Reputation: 29
I want to check if the "login page" appear before each step :
Here is my code:
casper.then(function() {
checkIfRedirectedToLoginPage();
this.evaluate(function() {
document.getElementById("").click();
});
});
casper.then(function() {
checkIfRedirectedToLoginPage();
this.evaluate(function() {
});
});
function checkIfRedirectedToLoginPage(){
if loginPage{
this.then(function(){
this.sendKeys(x('//*[@id="user_name"]'), USER_NAME);
this.sendKeys(x('//*[@id="password"]'),PASSWORD);
this.click(x(//*[@id="login"]));
});
}
}
How it's possible to override casper.then
without littering my code with the checkIfRedirectedToLoginPage function . thanks
Upvotes: 0
Views: 57
Reputation: 1372
it is possible to do this though it is not recommended. what I would suggest instead is to create a helper method that calls casper.then
and accepts a function as a callback.
function myCasperThen(callback) {
return casper.then(function() {
checkIfRedirectedToLoginPage();
callback();
}
}
Upvotes: 0