我使用PHPUnit_Selenium
延伸和遇到一些不受歡迎的行爲,如果一個元素不存在:PHPUnit_Selenium:如果找不到元素,請不要拋出異常?
Selenium測試案例:
$this->type('id=search', $searchTerm);
測試輸出:
RuntimeException: Invalid response while accessing the Selenium Server at 'http: //localhost:4444/selenium-server/driver/': ERROR: Element id=search not found
所以,我得到一個錯誤,但我想轉換它○失敗代替
我認爲是這樣的:
try {
$this->type('id=search', $searchTerm);
} catch (RuntimeException $e) {
$this->fail($e->getMessage());
}
但我真的不希望將所有運行時異常對故障轉換並沒有看到一個乾淨的方式來區分它們。
一個額外的斷言將是偉大的,但我找不到一個適合我的需要。例如:
$this->assertLocatorExists('id=search'); // ???
$this->type('id=search', $searchTerm);
我錯過了什麼嗎?或者還有另一種我沒有想到的方法?
二手版本:
- 的PHPUnit 3.7.14
- PHPUnit_Selenium 1.2.12
- Selenium服務器2.30.0
您指出我在正確的方向,謝謝! – 2013-03-06 13:37:25