verifyText 等方法不报告失败的行号,因此很难找到失败点。
Selenium 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'");
}
}
注意:为了让堆栈跟踪返回对我的断言代码的引用,我正在使用堆栈跟踪黑客