为什么选择browser.text.include?在Watir Ruby脚本中产生错误

为什么选择browser.text.include?在Watir Ruby脚本中产生错误,ruby,rspec,watir,Ruby,Rspec,Watir,问题:我在网上研究了如何验证我的页面上是否存在文本,但我一直收到错误消息。我尝试使用expect和一个unexpect。对于一些看似基本的东西,我不确定为什么这不是正确的断言 Ruby文件: 错误: test2.rb:61:in:main:Object NoMethodError的未定义methodexpect 您应该在测试用例中定义您的期望 describe "IE" do it "should have test 'Welcome'" do expect(@browser.te

问题:我在网上研究了如何验证我的页面上是否存在文本,但我一直收到错误消息。我尝试使用expect和一个unexpect。对于一些看似基本的东西,我不确定为什么这不是正确的断言

Ruby文件:

错误:

test2.rb:61:in:main:Object NoMethodError的未定义methodexpect


您应该在测试用例中定义您的期望

describe "IE" do
  it "should have test 'Welcome'" do
     expect(@browser.text.include("Welcome")).to be_true
  end
end
或者,如果您只是想让您的脚本打印通过或失败,只需这样做

begin
 if @browser.text.include?("Welcome")
    puts "Test passed!"
  else
    puts "Test failed!"
  end
end

我使用了begin/end语句,但它显示为false。它位于div类、span id、text welcome下。我需要指定div、class、spanid吗?我试过了,但没有看到欢迎语。我使用了ReRecorder工具,它看起来很受欢迎。当我运行脚本时,它会打开一个新的IE浏览器窗口。我是否需要以某种方式将焦点更改到此窗口,以便它看到它,然后看到欢迎文本?这似乎可以识别新窗口:@browser.window:title=>1st Global path.use Do begin if@browser.text.include?欢迎测试通过!否则测试失败!结束
begin
 if @browser.text.include?("Welcome")
    puts "Test passed!"
  else
    puts "Test failed!"
  end
end