I am new to Protractor. I think I have this down when dealing with an Angular page, but can't figure it out for a non-Angular page. Any help would be appreciated.
describe('Search', function() {
it('should click Search button and wait for results', function() {
browser.driver.findElement(by.id('search')).click();
});
});
In protractor there are two types terms for on the page.
isPresent
ask if the element is exists on the page.isDisplayed
asks if the element is visible. If you are waiting for a page to load you need to wait forisDisplayed
, but that will error if it is not present, so wait forisPresent
first. I use a function to wait for an element.Then just call that function in your test.
Testing non-angular pages with Protractor can be tricky regarding waiting for stuff.
I suggest you upgrade Protractor to latest (1.5.0 as of now), use a custom function waitReady() that
browser.wait
for elements ready and rewrite your test like below. Note you can put everything within 1 spec if you like so.More details of why
waitReady
here.Note: remember to set ignore synchronization for testing a non-angular page:
You can set it before
browser.get
the non-angular page.I've suggested setting a high implicit wait in the past, e.g.
That hack allows to you avoid
waitReady
and keep using the standardBut has an ugly disadvantage when testing for elements NOT present, i.e. when testing for absent or non visible elements in which case it will wait 5 seconds (5000ms) in vane, e.g. when doing
Figured this out. I simply added the code below, after the click method:
Another Neat approach is to use "Expected Conditions" inside browser.wait - something like this:
You can get more details here: https://angular.github.io/protractor/#/api?view=ExpectedConditions