【问题标题】:|Appium - Ruby| How does one assert that certain text is not displayed on the screen|Appium - 红宝石|如何断言某些文本未显示在屏幕上
【发布时间】:2016-11-17 06:31:51
【问题描述】:

在一个场景中,我想断言文本“Something”没有显示在屏幕上。

这是针对移动 iOS 应用的测试。 这是一个 Appium 测试,在 Cucumber + Watir-Webdriver 中。步骤是用 Ruby 编写的。

这是我迄今为止对 RSpec 期望所做的尝试:

1

    Given /^I should NOT see text "([^"]*)" displayed$/ do |text|
  text_exact(text).displayed? == false
end

2

Given /^I should NOT see text "([^"]*)" displayed$/ do |text|
  expect(nil).to eq(text)
end

3

Given /^I should NOT see text "([^"]*)" displayed$/ do |text|
  expect('Something').to_not eq(text)
end

4

Given /^I should NOT see text "([^"]*)" displayed$/ do |text|
  expect(text).to eq(false)
end

显示元素时似乎有很多示例。但是,当您要断言某些文本未显示时,则缺少信息。 欢迎任何建议。

【问题讨论】:

    标签: ruby rspec cucumber watir-webdriver appium-ios


    【解决方案1】:

    我对 Appium 不熟悉,但应该是这样的:

    expect(foo).to_not include(text)

    foo 是您要检查的文本。

    to_not,或等效的not_to,将否定以下匹配器)。

    【讨论】:

      【解决方案2】:

      所有示例都将步骤定义中的文本与固定值进行比较。您应该将步骤定义中的文本与从浏览器检索到的文本进行比较。

      最简单的方法是检查文本是否不包含在浏览器文本的任何位置:

      expect(browser.text).not_to include(text)
      

      但是,如果页面很大和/或文本不是唯一的,这可能会导致误报。例如,假设页面是:

      <html>
        <body>
          <span id="error">Something wrong</span>
          <span>Something else</span>
        </body>
      </html>
      

      如果有“Something wrong”是不好的,但有“Something else”是好的,检查整个浏览器文本将失败。在这种情况下,最好将文本范围限定为不应包含文本的特定元素:

      expect(browser.span(id: 'error').text).not_to include(text)
      

      【讨论】:

      • 谢谢贾斯汀。这是 iOS 移动应用程序。除了browser.text,我还能用什么?
      • 您使用的是 Watir-Webdriver,对吗? browser 是你用来存储 Watir::Browser 实例的变量吗?
      • 是的。浏览器 = Watir::Browser.new DRIVER.to_sym, :http_client => 客户端
      • 这是我的步骤:Given /^I should NOT see text "([^"]*)" displayed$/ do |text| expect(browser.text).not_to include(text) end ,这是小黄瓜:And I should NOT see text "Something" displayed。我确实收到一个错误:undefined local variable or method browser' for #<0x00000101e97f30>
      【解决方案3】:

      解决方案位于 Appium/Issues,这里: https://github.com/appium/appium/issues/6675

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-12-30
        • 1970-01-01
        • 1970-01-01
        • 2017-08-11
        • 1970-01-01
        • 2020-12-19
        • 1970-01-01
        相关资源
        最近更新 更多