Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit waits in phpunit selenium2 extension

For C# there is a way to write a statement for waiting until an element on a page appears:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
    {
        return d.FindElement(By.Id("someDynamicElement"));
    });

But is there a way to do the same in phpunit's selenium extension?

Note 1

The only thing I've found is $this->timeouts()->implicitWait(), but obviously it's not what I'm looking for.

Note 2

This question is about Selenium2 and PHPUnit_Selenium2 extension accordingly.

like image 667
zerkms Avatar asked Dec 28 '12 03:12

zerkms


1 Answers

The implicitWait that you found is what you can use instead of waitForCondition. As the specification of WebDriver API (that you also found ;)) states:

implicit - Set the amount of time the driver should wait when searching for elements. When searching for a single element, the driver should poll the page until an element is found or the timeout expires, whichever occurs first.

For example, this code will wait up to 30 seconds for an element to appear before clicking on it:

public function testClick()
{
    $this->timeouts()->implicitWait(30000);
    $this->url('http://test/test.html');
    $elm = $this->clickOnElement('test');
}

The drawback is it's set for the life of the session and may slow down other tests unless it's set back to 0.

like image 98
meze Avatar answered Oct 22 '22 22:10

meze