Ruby 如何使用capybara+;小型试验

Ruby 如何使用capybara+;小型试验,ruby,selenium,automation,capybara,minitest,Ruby,Selenium,Automation,Capybara,Minitest,我目前有一个def可以在下面执行此操作,但我觉得这是低效的,可能还有其他方法可以执行此操作。我知道Rspec有or()函数来帮助它,但水豚似乎没有这个功能 def assert_either_selector(selector_1, selector_2) if has_selector?(selector_1, wait: false) assert_selector(selector_1) elsif has_selector?(selector_2, wait: false

我目前有一个def可以在下面执行此操作,但我觉得这是低效的,可能还有其他方法可以执行此操作。我知道Rspec有or()函数来帮助它,但水豚似乎没有这个功能

def assert_either_selector(selector_1, selector_2)
  if has_selector?(selector_1, wait: false)
    assert_selector(selector_1)
  elsif has_selector?(selector_2, wait: false)
    assert_selector(selector_2)
  else
    flunk("Failed to match either selector \nExpected to find either: \n\t#{selector_1} or #{selector_2}")
  end
end

水豚确实支持
,但只有在使用RSpec匹配器时才支持(
期望(第页)。有_选择器(选择器_1)或(有_选择器(选择器_2))
),因为minitest不支持同时求值
。假设
selector_1
selector_2
是CSS选择器,那么这里最简单的解决方案就是使用CSS逗号和do

assert_selector("#{selector_1}, #{selector_2}")

这将检查与两个选择器中的任何一个匹配的元素。

@Nils\e注意:下一个水豚版本(3.10)可能(目前在主分支中)会有assert\u any\u选择器来补充现有assert\u all\u选择器和assert\u none\u选择器,以便能够用于相同的事情。