phpunit selenium2扩展中的显式等待

phpunit selenium2扩展中的显式等待,php,testing,selenium,phpunit,selenium-webdriver,Php,Testing,Selenium,Phpunit,Selenium Webdriver,对于C#,有一种方法可以编写语句,等待页面上的某个元素出现: WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10)); IWebElement myDynamicElement = wait.Until<IWebElement>((d) => { return d.FindElement(By.Id("someDynamicElement")); });

对于C#,有一种方法可以编写语句,等待页面上的某个元素出现:

WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(10));
IWebElement myDynamicElement = wait.Until<IWebElement>((d) =>
    {
        return d.FindElement(By.Id("someDynamicElement"));
    });
WebDriverWait wait=new-WebDriverWait(驱动程序,TimeSpan.FromSeconds(10));
IWebElement myDynamicElement=等待直到((d)=>
{
返回d.FindElement(By.Id(“someDynamicElement”);
});
但是在phpunit的selenium扩展中有没有同样的方法

附注1 我唯一找到的是
$this->timeouts()->implicitWait()
,但显然这不是我想要的

附注2
这个问题是关于Selenium2和PHPUnit_Selenium2扩展的。根据我的经验,从PHPUnit调试selenium测试用例非常困难,更不用说维护它们了。我在项目中使用的方法是使用Selenium IDE,将测试用例存储为.html文件,并仅通过phpunit调用它们。如果有什么问题,我可以从IDE中找到它们,并用一种更简单的方法进行调试。Selenium IDE有waitForElementPresent、waitForTextPresent,可能还有其他一些方法,可以解决您的问题。如果您想尝试一下,可以在继承自Selenium测试用例类的类中使用此方法

    $this->runSelenese("/path/to/test/case.html");

您找到的
implicitWait
是可以用来代替waitForCondition的。 正如(您也发现;)的规范所述:

隐式-设置驱动程序在搜索元素时应等待的时间量。当搜索单个元素时,驱动程序应该轮询页面,直到找到元素或超时过期为止,以先发生的为准

例如,此代码将在单击某个元素之前等待30秒,直到该元素出现:

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

缺点是它设置为会话的生命周期,并且可能会减慢其他测试,除非它设置为0。

问题是关于
PHPUnit\u Selenium2
和Selenium WebDriver。当然,这只是为了防止你没有想到这样的解决方案,我实际上正在考虑添加一个方法,比如官方java和c#客户端必须phpunit:-)@hek2mgl:没有进一步研究或发送PR-
implicitWait()
满足我的要求。我刚刚开始使用phpunit和Selenium,在这种情况下,OP希望等待加载某个元素,是否可以使用if-else条件,如果未找到该元素,请再等待一段时间,一旦找到,继续测试函数的其余部分?@Anagio这就是问题所在。只需使用
implicitWait()
。只有在找不到元素时,它才会等待该元素。如果找到它,测试函数的其余部分将继续进行,不会暂停。如果在指定的时间内没有找到它,比如30000,测试是否失败并在那里结束?@Anagio Yes,它失败了。