Commit 8064b0da19cedbb3d8089e9fd62e208857aea0ef

Authored by Rafael Manzo
1 parent a3cf9ea4

Fix selenium click link web step

Selenium tests were broken in clicking inside the content selection box.

Some HTML structures, such as `<li>` tags nested to `<a>` tags, may not
get along with Selenium and the browser interaction. But are perfectly
fine for the final user.

As we do not want to modify the current behaviour in order to pass
tests, here we handle Selenium's error properly so tests can still pass
without modifying current code.

NOTICE: This only works with selenium-webdriver 2.50.0 and up.
Showing 1 changed file with 16 additions and 1 deletions   Show diff stats
features/step_definitions/web_steps.rb
... ... @@ -39,7 +39,22 @@ end
39 39  
40 40 When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
41 41 with_scope(selector) do
42   - click_link(link, :match => :prefer_exact)
  42 + begin
  43 + click_link(link, :match => :prefer_exact)
  44 + rescue Selenium::WebDriver::Error::UnknownError => selenium_error
  45 + if selenium_error.message.start_with? 'Element is not clickable at point'
  46 + href = find_link(link)[:href]
  47 +
  48 + warn "#{selenium_error.message}\n\n"\
  49 + "Trying to overcome this by redirecting you to the link's href:\n"\
  50 + "\t'#{href}'\n\n"\
  51 + "Good luck and be careful that this may produce hidden links to work on tests!\n"
  52 +
  53 + visit href
  54 + else
  55 + raise selenium_error
  56 + end
  57 + end
43 58 end
44 59 end
45 60  
... ...