selenium IDE生成的模式总是错误的?

时间:2016-01-06 08:07:03

标签: php regex selenium phpunit preg-match

我正在通过从selenium IDE导出来在php中编写selenium测试用例。每当我在IDE中使用verifyText时,它在php中生成preg_match断言,在所有不同的情况下都会失败。这是其中之一,

try {
    $this->assertTrue((bool)preg_match('/^exact:Wachtwoord vergeten[\s\S]$/',$this->getText("link=exact:Wachtwoord vergeten?")));
} catch (PHPUnit_Framework_AssertionFailedError $e) {
        array_push($this->selenium->verificationErrors, $e->toString());
}

该脚本是从selenium IDE自动生成的。我不知道我做错了什么,或者我在IDE中做了哪些改变才能做到这一点?由于它是从IDE自动生成的,所以我不想在代码中进行更改来修复它。

任何帮助或建议都将不胜感激。

1 个答案:

答案 0 :(得分:0)

我的猜测是getText结果与您要查找的结果不匹配。您可以尝试this url并将搜索字符串(^ exact:Wachtwoord vergeten [\ s \ S] $)与getText()的结果进行比较。它经常发生在我身上,解决方法是简单地从搜索字符串中删除'exact:'字符串。 在你的情况下:

try {
    $this->assertTrue((bool)preg_match('/^Wachtwoord vergeten[\s\S]$/',$this->getText("link=exact:Wachtwoord vergeten?")));
} catch (PHPUnit_Framework_AssertionFailedError $e) {
        array_push($this->selenium->verificationErrors, $e->toString());
}