Reputation: 137
I am testing a page that will sometimes render one widget, and sometimes another.
I am trying to use browser.wait()
to ensure that ONE of the two has rendered, before going on to interact with the appropriate one depending on WHICH it is.
Here is my code:
EC = protractor.ExpectedConditions
browser.wait(() => {
return EC.presenceOf(userField) || EC.presenceOf(notMyAccountElement)
}, WAIT_TIME, 'Lock form (auth0) never appeared.')
notMyAccountElement.isPresent().then((result) => {
if (result) {
notMyAccountElement.click()
browser.wait(EC.presenceOf(userField), WAIT_TIME, 'New lock form (auth0) never appeared.')
}
userField.sendKeys(user)
passField.sendKeys(password)
submitBtn.click()
})
This usually works, but I get intermittent failures at:
userField.sendKeys(user)
I can see in the browser that occasionally this line executes when it is actually notMyAccountElement
that is present on the page.
I think the most likely problem is that the opening browser.wait()
is not resolving the way I am expecting it to, but I'd like to understand why.
Upvotes: 2
Views: 57
Reputation: 473833
I think you are not applying the expected conditions correctly, you need to use EC.or()
:
browser.wait(EC.or(EC.presenceOf(userField), EC.presenceOf(notMyAccountElement)),
WAIT_TIME, 'Lock form (auth0) never appeared.')
And, since you are interacting with userField
, you should be probably using the visibilityOf
or elementToBeClickable
instead of presenceOf
expected condition. Though, I doubt it is related to the intermittent failures.
You may also change the wait from waiting for presence/visibility of userField
to invisibility/staleness of the notMyAccountElement
. Replace:
browser.wait(EC.presenceOf(userField), WAIT_TIME, 'New lock form (auth0) never appeared.');
with:
browser.wait(EC.stalenessOf(notMyAccountElement), WAIT_TIME, 'New lock form (auth0) never appeared.');
Or, you may use both, one by one, to make things even more reliable.
Upvotes: 4