Expected conditions in the protractor

When writing selenium tests in Python, I’m used to using Explicit Waits repeatedly to wait for a page to load or to wait for an element to become visible, or clickable, etc.:

from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC element = WebDriverWait(driver, 10).until( EC.presence_of_element_located((By.ID, "myDynamicElement")) ) 

The key concept here is to provide the expected condition for the wait; there are several types:

Using the expected conditions makes the code cleaner and more reliable than using sleep with hard-coded time intervals.

Now we are moving from our end-to-end testing infrastructure to a lot of protractor .

Are there similar Expected Conditions in the transporter as it is in python-selenium or java-selenium ? If not, what is the canonical way to explicitly wait for a condition in a protractor ?

I looked through the documentation documentation and found nothing about it.

+9
python selenium testing selenium-webdriver protractor
Jan 02 '15 at 4:22
source share
3 answers

Once feat (expectedConditions) is found (probably protractor 1.7), you can do:

 var EC = protractor.ExpectedConditions; var e = element(by.id('xyz')); browser.wait(EC.presenceOf(e), 10000); expect(e.isPresent()).toBeTruthy(); 

Note that if you are working with an Angular application and your test requires these conditional expectations, this is a big red flag for what you are doing, since the protractor should handle the expectations initially.

+15
Jan 09 '15 at 18:55
source share

In Protractor you can use browser.wait(fn, timeout) .

Example:

 var element = by.id('myDynamicElement'); browser.wait(function() { return ptor.isElementPresent(element); }, 10000); expect(ptor.isElementPresent(element)).toBeTruthy(); 
+1
Jan 02 '15 at 6:51
source share
 waitForControlVisible(locator: string, timeout: number) { try { const element = this.findElement(locator); const condition = browser.ExpectedConditions; browser.wait(condition.visibilityOf(element), timeout); } catch (e) { console.log(e.message); console.error('Control not visible.', e); } } 

Perhaps it will help you, wait until the elements are visible in the DOM.

0
Jun 23 '17 at 6:22
source share



All Articles