Netbeans 硒PHP“;核实;不包括行号
verifyText等方法不报告故障行号,因此很难找到故障点 Selenium IDE PHPUnit导出创建的代码如下所示:Netbeans 硒PHP“;核实;不包括行号,netbeans,selenium,phpunit,Netbeans,Selenium,Phpunit,verifyText等方法不报告故障行号,因此很难找到故障点 Selenium IDE PHPUnit导出创建的代码如下所示: try { $this->assertEquals($text, $this->getTitle()); } catch (PHPUnit_Framework_AssertionFailedError $e) { array_push($this->verificationErrors, $e->toString()); } 这
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'");
}
}
注意:为了使stacktraces返回对我的资产代码的引用,我使用了创建此验证方法的stacktrace,包括(太多)stacktrace:
public function appendVerification($message,$e) {
array_push($this->verificationErrors,$message."\n".$this->dumpStack($e));
}
我还更新了PHPUnit测试中引用的dumpStack方法,以按类名自动剥离框架调用
protected function dumpStack(Exception $e) {
$stack = '';
foreach ($e->getTrace() as $trace) {
if (isset($trace['file']) &&
isset($trace['line'])) {
if (!isFramework($trace['file']))
$stack .= PHP_EOL .
$trace['file'] . ':' .
$trace['line'] . ' ';
}
}
return $stack;
}
function isFramework($fileName) {
$test = ((preg_match("/PHPUnit/i",$fileName) +
preg_match("/php.phpunit/i",$fileName)) > 0);
return $test;
}
最终结果,可在netbeans中单击,无任何PHPUnit框架行号
Failed asserting that 'waitForElementPresent failed for selector: css=input#address.valid' is false.
C:\dev\Automation_Dev\phpTests\library\SeleniumUtilsTestCase.php:228
C:\dev\Automation_Dev\phpTests\library\SeleniumUtilsTestCase.php:115
C:\dev\Automation_Dev\phpTests\library\SeleniumTestCase.php:176
C:\dev\Automation_Dev\phpTests\usecases\CreateListingTest.php:72
C:\dev\Automation_Dev\phpTests\usecases\CreateListingTest.php:39
C:\dev\Automation_Dev\phpTests\usecases\CreateListingTest.php:23
C:\xampp\php\phpunit:46