2016-11-28 38 views
1

我使用PHP Webdriver進行測試。在我的測試之一,警報:php webdriver - 等待警報,不殺死測試用例

要顯示此頁面,火狐必須發送進行,這將重複 任何操作(如搜索或其他確認)信息 較早

預計會出現。

如何指示Webdriver等待警報出現?例如 - 最大等待超時時間如60秒,如果警報在15秒後出現,我希望Webdriver讓我知道它存在。

screenshot of the alert enter image description here

回答

0

PHP版本(找語法錯誤,因爲我不熟悉PHP):

// wait for at most 60s for the alert 
// sleep for 500ms and retries if it the alert is present. 
// return alert if present, otherwise null 
$driver->wait(60, 500)->until(
    WebDriverExpectedCondition::alertIsPresent() 
); 

注: 60秒500毫秒的配置根據您的需要。

參考文獻:

  1. https://github.com/facebook/php-webdriver/wiki/HowTo-Wait
  2. https://facebook.github.io/php-webdriver/classes/WebDriverExpectedCondition.html#method_alertIsPresent

的Java版本

WebDriverWait wait = new WebDriverWait(driver, 60); //60 seconds- configurable 
Alert alert = wait.until(ExpectedConditions.alertIsPresent()); 
alert.accept();