Commit 00c832e060d2f872c233b7745e84bebdeb429465
1 parent
c7574edc
Exists in
master
and in
12 other branches
Fix follow step on selenium
Showing
1 changed file
with
8 additions
and
30 deletions
Show diff stats
features/step_definitions/web_steps.rb
@@ -39,37 +39,15 @@ end | @@ -39,37 +39,15 @@ end | ||
39 | 39 | ||
40 | When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| | 40 | When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| |
41 | with_scope(selector) do | 41 | with_scope(selector) do |
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 | - link = find_link(link) | ||
47 | - href = link[:href] | ||
48 | - onclick = link[:onClick] | ||
49 | - | ||
50 | - warn "#{selenium_error.message}\n\n"\ | ||
51 | - "Trying to overcome this by:\n" | ||
52 | - | ||
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" | ||
69 | - else | ||
70 | - raise selenium_error | ||
71 | - end | 42 | + link = find :link_or_button, link, match: :prefer_exact |
43 | + # If the link has child elements, then $(link).click() has no effect, | ||
44 | + # so find the first child and click on it. | ||
45 | + if Capybara.default_driver == :selenium | ||
46 | + target = link.all('*').first || link | ||
47 | + else | ||
48 | + target = link | ||
72 | end | 49 | end |
50 | + target.click | ||
73 | end | 51 | end |
74 | end | 52 | end |
75 | 53 |
-
mentioned in commit 20bfd7e00bb45965858e8cf8ed7202a1cf7ffb46