Check elements from array are not visible

236 views Asked by At

I have an array with elements' names:

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

And I wan't to check that they are not visible:

expect(actual).to all(not_be_visible)

But be_not_visible, not_visible, not_be_visible, .not_to all(be_visible) are not correct methods. What method is correct?

2

There are 2 answers

0
Justin Watts On

You can check the array without iterating through it yourself but using the include & all matchers/modifiers. The best ones for this case would be .not_to + include.

expect(names).not_to include(be_visible)

A less sexy solution would be to match !(false) which = true.

expect(names).to all(!(be_visible))
0
MilesStanfield On

Loop through each name and ensure the page does not have that text:

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

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