JTApps February 2016

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

Easier explained with pseudocode in my opinion:

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

Does there exist an effective way to perform this test using Capybara and Ruby/Cucumber?

Answers


Tom Walpole February 2016

The following should do what you're trying to do

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


Sarabjit Singh February 2016

The following piece of code can be an effective way to verify if there is at least one table row on the page containing an arbitrary number of strings:

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

Hope this helps :)

Post Status

Asked in February 2016
Viewed 1,478 times
Voted 13
Answered 2 times

Search




Leave an answer