Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby “browser.text.include?”返回误报?(watir webdriver和cucumber)_Ruby_Selenium_Cucumber_Watir Webdriver - Fatal编程技术网

Ruby “browser.text.include?”返回误报?(watir webdriver和cucumber)

Ruby “browser.text.include?”返回误报?(watir webdriver和cucumber),ruby,selenium,cucumber,watir-webdriver,Ruby,Selenium,Cucumber,Watir Webdriver,基本上,我希望在提交带有空必填字段的表单时检查错误消息 def usertabfieldvalidation @session.button(:class, "btn-primary").click @session.text.include? 'Giant Gerbils of the world unite' end 这一步过去了。我想检查文本,请填写此字段,但我查找的任何文本都将通过。我对ruby和watir webdriver还比较陌生,所以想知道我哪里出了问题 提前感谢。所以我将RS

基本上,我希望在提交带有空必填字段的表单时检查错误消息

def usertabfieldvalidation
@session.button(:class, "btn-primary").click
@session.text.include? 'Giant Gerbils of the world unite'
end
这一步过去了。我想检查文本,请填写此字段,但我查找的任何文本都将通过。我对ruby和watir webdriver还比较陌生,所以想知道我哪里出了问题


提前感谢。

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

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

我将include-RSpec::Matchers添加到包含所需方法的类中,然后将方法更新为

expect@session.text.to包括“请填写此字段”


这似乎起到了作用。谢谢

还有更多的代码吗?没有触发失败的断言。这是有道理的,但我不知道如何编写。你能给我一个断言的例子吗?这取决于你使用的测试框架。例如,RSpec将具有expect@session.text.to包括“请填写此字段”。在小型测试中,你会assert@session.text.include?请填写此字段。有点过时了,但是Watir的网页上有一些例子-。框架是cucumber,我会看看这些例子,看看我能找到什么。谢谢你的指点。