How can I verify that an item has been removed from the page, with Capybara and Selenium?

I am trying to write an integration test in Rails 3.0.8 using Capybara (head) and Selenium. I would like to verify that when the user clicks the delete button for an item on my web page, the item is actually deleted. So, on the webpage, I am hiding the element with a jQuery fragment

$('#interaction').fadeOut(); 

and I use the following rspec test and set Capybara.default_wait_time to 5 seconds, however nothing seems to let me pass the test. How can I check this correctly?

 describe "A User adding an Interaction" do describe "when looking at an Item detail page" do it "should be able to delete and existing interaction", :js => true do sign_in_and_view_item page.should have_content "ITEM DETAILS - #{@item.name}" fill_in "interaction-input", :with => "My Interaction" click_button "item-interaction-submit" page.should have_content "My Interaction" click_link "Delete Interaction" wait_until do page.evaluate_script('$.active') == 0 end #page.should_not have_content "My Interaction" page.should have_no_content "My Interaction" end end end 
+4
source share
2 answers

I ended up adding this line to my spec / spec_helper.rb

 Capybara.ignore_hidden_elements = false 

using this specification

spec_helper required

 describe "A User adding an Interaction" do describe "when looking at an Item detail page" do it "should be able to delete and existing interaction", :js => true do sign_in_and_view_item page.should have_content "ITEM DETAILS - #{@item.name}" fill_in "interaction-input", :with => "My Interaction" click_button "Save" page.should have_content "My Interaction" click_link "Delete Interaction" should_be_hidden "My Interaction" end end end 

along with this function should_be_hidden

 def should_be_hidden text, selector='' sleep Capybara.default_wait_time its_hidden = page.evaluate_script("$('#{selector}:contains(#{text})').is(':hidden');") its_not_in_dom = page.evaluate_script("$('#{selector}:contains(#{text})').length == 0;") (its_hidden || its_not_in_dom).should be_true end 
+3
source

Does capybara 2.1 support has_text? , which takes a parameter of type :visible , which will check the page for all visible text.

http://rubydoc.info/github/jnicklas/capybara/master/Capybara/Node/Matchers#has_text%3F-instance_method

0
source

All Articles