【问题标题】:Check elements from array are not visible数组中的检查元素不可见
【发布时间】:2015-12-09 15:13:20
【问题描述】:

我有一个包含元素名称的数组:

names=['tdColumn1','tdColumn2','tdColumn3']

而且我不想检查它们是否不可见:

expect(actual).to all(not_be_visible)

be_not_visiblenot_visiblenot_be_visible.not_to all(be_visible) 不是正确的方法。 什么方法是正确的?

【问题讨论】:

  • 这些是html元素吗?
  • 是的,他们是。通过页面对象描述
  • 你能分享你想要处理的html代码部分吗?
  • 这只是一个简单的 TD,当我选中/取消选中复选框时,它会变得可见/不可见。当我检查可见性expect(actual).to all(be_visible) 时,它可以工作。但我需要一种检查隐形的方法。
  • 哦,确实。奇怪的。无论如何:expect(actual.map(&:visible?)).to all(be_falsey)

标签: ruby rspec watir page-object-gem rspec-expectations


【解决方案1】:

遍历每个名​​称并确保页面没有该文本:

names=['tdColumn1','tdColumn2','tdColumn3']

names.each do |name|
  expect(page).not_to have_text name
end

【讨论】:

    【解决方案2】:

    您可以检查数组,而无需自己迭代,而是使用包含和所有匹配器/修饰符。这种情况下最好的方法是 .not_to + include。

    expect(names).not_to include(be_visible)
    

    一个不那么性感的解决方案是匹配 !(false) which = true。

    expect(names).to all(!(be_visible))
    

    【讨论】:

      猜你喜欢
      • 2017-05-23
      • 2017-02-28
      • 2012-09-18
      • 2013-06-28
      • 2013-11-09
      • 2022-01-07
      • 2017-08-10
      • 2017-01-01
      相关资源
      最近更新 更多