Commit 7c6af440566b211e0afc80a6750f4bfe3091c3c2

Authored by Rafael Manzo
1 parent 94630012

Fix selenium onClick link web step

The previous fix at 8064b0da19cedbb3d8089e9fd62e208857aea0ef did not
expect links with onClick actions which was specially breaking
the category_block feature.
Showing 1 changed file with 20 additions and 5 deletions   Show diff stats
features/step_definitions/web_steps.rb
@@ -43,14 +43,29 @@ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| @@ -43,14 +43,29 @@ When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
43 click_link(link, :match => :prefer_exact) 43 click_link(link, :match => :prefer_exact)
44 rescue Selenium::WebDriver::Error::UnknownError => selenium_error 44 rescue Selenium::WebDriver::Error::UnknownError => selenium_error
45 if selenium_error.message.start_with? 'Element is not clickable at point' 45 if selenium_error.message.start_with? 'Element is not clickable at point'
46 - href = find_link(link)[:href] 46 + link = find_link(link)
  47 + href = link[:href]
  48 + onclick = link[:onClick]
47 49
48 warn "#{selenium_error.message}\n\n"\ 50 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" 51 + "Trying to overcome this by:\n"
52 52
53 - visit href 53 + onclick_return = true
  54 +
  55 + unless onclick.nil?
  56 + warn "\t* Running onClick JS:\n"\
  57 + "\t\t'#{onclick}'\n"
  58 + onclick_return = page.execute_script onclick
  59 + end
  60 +
  61 + if onclick_return
  62 + warn "\t* Redirecting you to the link's href:\n"\
  63 + "\t\t'#{href}'\n"
  64 +
  65 + visit href
  66 + end
  67 +
  68 + warn "\nGood luck and be careful that this may produce hidden links to work on tests!\n"
54 else 69 else
55 raise selenium_error 70 raise selenium_error
56 end 71 end