验证页面上至少有一个 table 行包含任意数量的字符串

Verify there is at least one table row on the page containing an arbitrary number of strings

我认为用伪代码更容易解​​释:

page.all('tr').each do |tr|
    if tr.has_text?(string1) and tr.has_text?(string2) # and so on...
        # Pass the test!
    end
end
# Else fail the test

是否存在使用水豚和 Ruby/Cucumber 执行此测试的有效方法?

以下内容应该可以满足您的要求

strings = [string1, string2, ...]
found = page.all('tr').any? do |tr|
  strings.all? { |s| tr.has_text?(s, wait: 0) }
end
expect(found).to be true

下面的一段代码可以有效地验证页面上是否至少有一个 table 行包含任意数量的字符串:

found = false
  page.all(:css, 'tr').each do |row|
    if row.text != ""
      found = true
    end
  end
found.should eq true

希望这对您有所帮助:)