Capybara: page.should have_no_content not working correctly for display: none element

I would like to use page.should have_no_content to check if the page does not display a shortcut for the user, here is what it is in HTML:

<li id="account_input" style="display: none;"> <label for="account_name">My Account</label> ... </li> 

Therefore, when I use page.should have_no_content ("My Account"), it returns false instead of true.

+8
ruby-on-rails integration-testing cucumber capybara
source share
4 answers

I found a solution using:

 Then /^"([^\"]+)" should not be visible$/ do |text| paths = [ "//*[@class='hidden']/*[contains(.,'#{text}')]", "//*[@class='invisible']/*[contains(.,'#{text}')]", "//*[@style='display: none;']/*[contains(.,'#{text}')]" ] xpath = paths.join '|' page.should have_xpath(xpath) end 
+3
source share

You can use this operator

 find('#account_input').should_not be_visible 
+12
source share

I found another way to implement, should not

page.should_not (has_content (arg1))

0
source share

Therefore, when I use page.should have_no_content ("My Account"), it returns false instead of true.

This should be wrong. Think of it this way: if your page has โ€œMy Accountโ€ content, then has_content will return True, so has_no_content should return False. And the reason is not true to say that HTML does not contain the content "My Account". So this is False.

-one
source share

All Articles