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