问题
waitForAngularEnabled doesn't seem to work.
Use case : - waitForAngularEnabled to false to get sso page and fill user/password fields - return to angular app and waitForAngularEnabled to true causes error
i've create a simple angular app projet to reproduce it, simple run ng e2e
https://github.com/lilletech/protractor-issue
回答1:
You should break your tests up more, both for your sake with debugging and to mitigate issues with the protractor control flow. Changing your tests to the following works:
import { browser, element, by } from 'protractor';
describe('protractor-test-project App', () => {
it('goes to google', () => {
browser.waitForAngularEnabled(false);
browser.get('https://www.google.com');
expect(browser.getCurrentUrl()).toEqual('https://www.google.com/');
});
it('enters a search', () => {
const inputEl = element(by.id('lst-ib'));
browser.wait(() => inputEl.isPresent(), 10000, 'too long');
inputEl.sendKeys("protractor issue waitForAngularEnabled");
expect(inputEl.getAttribute('value')).toEqual('protractor issue waitForAngularEnabled');
});
it('returns to angular page', () => {
browser.get('/');
browser.waitForAngularEnabled(true);
const titleElement = element(by.id("title"));
expect(titleElement.isPresent());
});
});
Can't say for sure why the control flow wouldn't be handling this properly, but this seems to be caused by having two waitForAngularEnabled
in the same spec (also might be because of navigating twice). If you disable your second one (where you re-enable it), your test works.
So you can either use my solution above which breaks them out into multiple steps, or you can nest the call under browser.get
which also seems to work i.e.
browser.get('/').then(() => {
browser.waitForAngularEnabled(true);
});
Again, not sure why exactly that would happen. The control flow should be synchronizing these steps so using .then()
shouldnt be necessary... but apparently it is. Breaking tests out into multiple it
blocks also helps protractor synchronize things in the proper order
来源:https://stackoverflow.com/questions/51261318/protractor-waitforangularenabled