I am struggling with finding a way to test my angularjs application that has a non-angular login page.
All of the app's pages are protected by a login, so whatever page I test, I will need to login first. I have looked through all kinds of ideas on the internet and nothing seems to work - it just doesn't redirect me to the app after logging in with protractor, while all works great when I do it manually.
This is what I have at the moment:
onPrepare: function() {
browser.driver.get('http://localhost:9000/app);
browser.driver.findElement(by.id('userName')).sendKeys('admin');
browser.driver.findElement(by.id('password')).sendKeys('pass123');
browser.driver.findElement(by.id('loginBtn')).click();
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /home/.test(url);
});
}, 10000);
I have also tried with setting browser.ignoreSynchronization = true;
but still got nowhere.
Does anybody know what else I can try?
Set ignoreSynchronization=true
before browser.get()
, and reset to false
after click login button.
onPrepare: function() {
browser.ignoreSynchronization = true;
browser.driver.get('http://localhost:9000/app);
browser.driver.findElement(by.id('userName')).sendKeys('admin');
browser.driver.findElement(by.id('password')).sendKeys('pass123');
browser.driver.findElement(by.id('loginBtn')).click();
browser.ignoreSynchronization = false;
return browser.driver.wait(function() {
return browser.driver.getCurrentUrl().then(function(url) {
return /home/.test(url);
});
}, 10000);
if above code not fix your issue, try to move above code for login into a function and don't call the function in onPrepare
, call the function like in beforeAll
. I had some fail experience start to interact with browser inside onPrepare