Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
125
rated 0 times [  129] [ 4]  / answers: 1 / hits: 16259  / 10 Years ago, fri, july 25, 2014, 12:00:00

My Protractor e2e tests are inconsistently passing and failing.



It seems this could be due to asynchronous javascript, as discussed here:
Protractor : How to wait for page complete after click a button?.



However, here it's mentioned that Protractor tests automatically execute sequentially / synchronously:
https://github.com/angular/protractor/issues/909



My test script:



describe('Login', function() {

var ptor;

beforeEach(function() {
browser.get('https://127.0.0.1:8443');
ptor = protractor.getInstance();
element(by.id('splash')).click();
browser.ignoreSynchronization = true; // <-- to proceed beyond splash screen
});

describe('with correct email and password', function() {

beforeEach(function() {
element(by.id('email')).sendKeys('[email protected]');
element(by.id('password')).sendKeys('adminpassword');
element(by.id('loginButton')).click();
});

afterEach(function() {
ptor.findElement(by.id('logout')).then(function(elem) {
elem.click();
});
});

it('does not show alert', function() { // <-- sometimes passes, sometimes fails
expect(browser.isElementPresent(by.css('.alert-danger'))).toBe(false);
});

it('changes route to /admin', function() { // <-- sometimes passes, sometimes fails
expect(browser.getCurrentUrl()).toMatch(//admin/);
});
});
});


In the two tests above, either both tests will pass, or one/both of the tests will fail with these messages:



Failures:

1) Login with correct email and password does not show alert
Message:
NoSuchElementError: no such element
...
==== async task ====
WebDriver.findElement(By.id(logout))
...


or



Failures:

1) Login with correct email and password changes route to /admin
Message:
NoSuchElementError: no such element
...
==== async task ====
WebDriver.findElement(By.id(logout))
...


Thoughts / help much appreciated.


More From » angularjs

 Answers
7

I was able to resolve the issue based on the following:





As mentioned by Nguyen Vu Hoang's comment to the original question, I am testing a pure Angular app with what I think is pure Protractor (no webdriver calls). I know ptor.ignoreSynchronization=true should not be required in this case, but for some reason, the tests are not proceeding at button click without this setting.



My new spec:



describe('Login', function() {

var ptor;

beforeEach(function() {
ptor = protractor.getInstance();
ptor.ignoreSynchronization = true;
ptor.waitForAngular();
ptor.get('https://127.0.0.1:8443');
ptor.findElement(by.id('splash')).then(function(elem) {
elem.click();
});
});

describe('with correct email and password', function() {

beforeEach(function() {
ptor.findElement(by.id('email')).then(function(elem) {
elem.sendKeys('[email protected]');
});

ptor.findElement(by.id('password')).then(function(elem) {
elem.sendKeys('adminpassword');
});

ptor.findElement(by.id('loginButton')).then(function(elem) {
elem.click();
});
});

afterEach(function() {
ptor.findElement(by.id('logout')).then(function(elem) {
elem.click();
});
});

it('does not show alert', function() {
expect(ptor.isElementPresent(by.css('.alert-danger'))).toBe(false);
});

it('changes route to /admin', function() {
expect(ptor.getCurrentUrl()).toMatch(//admin/);
});
});
});

[#70047] Wednesday, July 23, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
neildrews

Total Points: 166
Total Questions: 103
Total Answers: 85

Location: Moldova
Member since Sat, Aug 6, 2022
2 Years ago
neildrews questions
Fri, Feb 18, 22, 00:00, 2 Years ago
Tue, Oct 12, 21, 00:00, 3 Years ago
Tue, Mar 23, 21, 00:00, 3 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
;