我正在使用 Watir WebDriver 和 Firefox 的测试/单元。
以下代码有效:
assert(@browser.text.include?("Company employees"))
为什么下面的代码不起作用?
assert(@browser.text.include?(/Company employees/))
我正在使用 Watir WebDriver 和 Firefox 的测试/单元。
以下代码有效:
assert(@browser.text.include?("Company employees"))
为什么下面的代码不起作用?
assert(@browser.text.include?(/Company employees/))
The String#include? method only accepts strings or characters. It does not accept regular expressions.
You can use either of the following to assert against the regexp:
assert(@browser.text.match(/Company employees/))
assert(@browser.text =~ /Company employees/)
assert(@browser.text[/Company employees/])
However, I think it is more clear (reading the code and the error message) if you use the assert_match:
assert_match(/Company employees/, @browser.text)
试试 assert(@browser.text.include?("/Company employees/"))