0
像verifyText這樣的方法不會報告失敗的行號,因此很難找到失敗點。Selenium PHP「驗證」失敗不包括行號
硒IDE PHPUnit的出口產生的代碼如下所示:
try {
$this->assertEquals($text, $this->getTitle());
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors, $e->toString());
}
此行輸出類似於下面的第2行,這是完全不可考
Failed asserting that '' matches PCRE pattern "/Harlem/".
Failed asserting that two strings are equal.
Failed asserting that '(Pattern A)' matches PCRE pattern "/\(Pattern B\)/".
我已經修改了調用包含引用的文本可以讓我搜索文本失敗,但是在大型測試中這是不夠的。我的代碼中如何獲取每次驗證失敗的行號/堆棧跟蹤?
public function verifyTitle($text) {
$title = $this->getTitle();
try {
$this->assertEquals($text, $title);
} catch (PHPUnit_Framework_AssertionFailedError $e) {
array_push($this->verificationErrors,
"Title is '$title' but should be '$text'");
}
}
注:爲了得到蹤跡返回引用到我的代碼斷言,我現在用的是stacktrace hack