我正在使用webdriver支持的selenium和java运行测试来验证包含%的错误消息,这导致测试失败。
我曾尝试使用UTF-8代码(\u0025
),但这也失败了。
代码:
assertTrue(
Pattern.compile(
"Please enter a password of between 6 and 20 characters. You may use lower or upper case letters a-z, numbers 0-9 and the following characters !\"£$%").
matcher(
selenium.getText(
"//form[@id='registrationForm']/fieldset[3]/div/div[2]/div/p")).
find());
答案 0 :(得分:1)
你正在使用正则表达式来匹配你的字符串($表示字符串/行的结尾)...如果你真的想要使用正则表达式我会建议:
...
Pattern.compile(
"Please enter a password of between 6 and 20 characters\\. You may use lower or upper case letters a-z, numbers 0-9 and the following characters !\"£\\$%").
matcher(
...
否则你可以这样做:
assertTrue(
selenium.getText("//form[@id='registrationForm']/fieldset[3]/div/div[2]/div/p")
.contains(
"Please enter a password of between 6 and 20 characters. You may use lower or upper case letters a-z, numbers 0-9 and the following characters !\"£$%"
));