【问题标题】:Watir Check Text existsWatir 检查文本是否存在
【发布时间】:2014-06-12 15:59:40
【问题描述】:

我得到它不是 Watir 与 rspec 一起找到我的文本。 以下代码会导致此错误。

  1. 代码:browser.text.include?("Coverberechnung").should == true
  2. 错误1:expected: true got: false (using ==)
  3. 错误2:Using should from rspec-expectations' old :should syntax without explicitly enabling the syntax is deprecated. Use the new :expect syntax or explicitly enable :should instead. Called from

也许我可以帮忙

网站网址:enter link description here

【问题讨论】:

    标签: ruby rspec watir watir-webdriver assertion


    【解决方案1】:

    您正在寻找一个首字母大写的字符串(即 Coverberechnung),但该字符串在测试站点上是全大写的(即 COVERBERECHNUNG)。 p>

    试试:

    browser.text.include?("COVERBERECHNUNG").should == true

    或(使用expect 语法)

    expect(browser.text.include?("COVERBERECHNUNG")).to be true

    【讨论】:

    • 使用期望语法,我必须使用“to be true”而不是“to be_true”,而不是那个upvote ;)。谢谢!
    【解决方案2】:

    我更喜欢使用 expect(browser.text).to include('coverberechnung')

    【讨论】:

      【解决方案3】:

      如果我想对案例漠不关心,我会这样做:

      browser.text.upcase.include?("COVERBERECHNUNG").should == true
      

      browser.text.downcase.include?("coverberechnung").should == true
      

      这样您可以避免可能有不同情况的文本比较。

      还有最后一个问题#3: 使用

      expect(browser.text.downcase.include?("coverberechnung")).to be true
      

      他们不久前弃用了该版本。所以你可以毫无问题地试一试。

      注意:只有一个警告是这将忽略大小写。如上所述。

      【讨论】:

        【解决方案4】:

        或者您可以执行以下操作:

        fail unless @browser.text.include? 'COVERBERECHNUNG'
        

        或者,如果您想定位那个确切的字符串,您可以改为执行以下操作:

        @browser.h1(text: 'COVERBERECHNUNG').wait_until_present
        

        如果此代码找不到带有以下文本的标题元素:“COVERBERECHNUNG”,该代码将在 30 秒后引发异常(因此,在此过程中您的测试失败)。您还可以通过执行以下操作来覆盖等待或轮询过程:

        @browser.h1(text: 'COVERBERECHNUNG').wait_until_present(10)
        

        该代码将在 10 秒内检查 h1 元素。

        【讨论】:

          猜你喜欢
          • 2020-10-05
          • 2012-10-15
          • 2019-01-19
          • 1970-01-01
          • 1970-01-01
          • 2019-09-28
          • 2023-03-15
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多