"browser.text.include?" 返回误报? (watir-webdriver & 黄瓜)

"browser.text.include?" returning false positives? (watir-webdriver & cucumber)

基本上我想在提交必填字段为空的表单时检查错误消息。

def usertabfieldvalidation
@session.button(:class, "btn-primary").click
@session.text.include? 'Giant Gerbils of the world unite'
end

这一步通过。我想检查文本 "Please fill out this field" 但我查找的任何文本都会通过。我是 ruby 和 watir-webdriver 的新手,所以想知道我哪里出错了?

提前致谢。

所以我将 RSpec 添加到我的 Gemfile 和 env.rb。

我仍然收到 expect 的方法未定义错误,因为我在我的步骤定义之外调用了一个方法。

我将 include RSpec::Matchers 添加到包含我想要的方法的 class,然后将方法更新为

expect(@session.text).to include('Please fill out this field')

这似乎成功了。谢谢!