문제

I'm using Watir WebDriver and test/unit with Firefox.

The following code works:

assert(@browser.text.include?("Company employees"))

Why does the following code not work?

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)

다른 팁

try assert(@browser.text.include?("/Company employees/"))

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top