1

I'm testing for deletion of records from an ActiveRecord class using Capybara/Selenium. The actual deletion is done using the Gherkin script (the xPath bit is so I can find the right user to delete):

When(/^I delete the other (.*)$/) do |role|
  visit '/users'
  page.evaluate_script('window.confirm = function() { return true; }')
  find(:xpath, %{//tr[td='Bob']/td[@class='list_actions']//a[@data-method='delete']}).click
end

Unfortunately when I check the list of users, Bob is still there. However, if I pause execution (using an ask statement) then when I resume sure enough Bob has gone. So it seems that Capybara is checking for Bob's existence before Selenium/Rails has got around to deleting him.

Googling for this, there seems to be a lot of confusion over whether Selenium waits on a click action, and all of the solutions I can find assume something is being added so they can wait until it appears -- not the case in my scenario.

So how can I get rid of this race condition -- make Selenium wait until the record has been deleted?

digitig
  • 1,989
  • 3
  • 25
  • 45

0 Answers0