I am having trouble getting the protractor to behave as expected when testing my angular app. My spec file looks like this:
describe('app login', function() { it('should allow admin user to log in', function() { browser.get('http://localhost:3008'); //we can find the log in link expect(element(by.id('login-link')).getText()).toContain('Log in'); //open login dialog element(by.id('login-link')).click(); browser.ignoreSynchronization = true; browser.sleep(1000); //enter credentials element(by.id('login-username')).sendKeys('User1'); element(by.id('login-password')).sendKeys('Password1'); browser.sleep(1000); //log in var el = element(by.id('login-btn')); //WORKS IF BELOW LINE IS COMMENTED OUT el.click(); browser.sleep(1000); //display confirms login expect(element(by.id('user-display')).getText()).toContain('User1'); }); });
Note that I was getting sync errors at the beginning, so I have the ignoreSynchronization flag set to true and all of these browser.sleeps files.
Now here's the thing: the test will go fine if I remove the el.click () statement (and the final call on hold). However, when this line is included, I get a NoSuchElementError: element not found using the locator: By.id ("login-username") . Note that this element is not the one I'm actually trying to click, which is part of the bizarre thing.
source share