Reputation: 254916
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?
The only thing I've found is $this->timeouts()->implicitWait()
, but obviously it's not what I'm looking for.
This question is about Selenium2 and PHPUnit_Selenium2 extension accordingly.
Upvotes: 7
Views: 3759
Reputation: 15087
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.
Upvotes: 8
Reputation: 7693
From my experience it is very hard to debug selenium test case from phpunit, not to mention maintaining them. The approach I use in my projects is to use Selenium IDE, store test cases as .html files and only invoke them via phpunit. If there is anything wrong, I can lunch them from IDE and debug in a much easier why. And Selenium IDE has waitForElementPresent, waitForTextPresent and probably some other method, which can solve your issue. If you want to give it a try, you can use this method in your class inheriting from Selenium Test Case class.
$this->runSelenese("/path/to/test/case.html");
Upvotes: 1