Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Capybara should retry when ClickFailed is raised

  • Loading branch information...
commit be6a055687426e24d57dae3d4aae905d7373e90a 1 parent 2c47aea
@mhoran mhoran authored
Showing with 31 additions and 1 deletion.
  1. +1 −1  lib/capybara/webkit/driver.rb
  2. +30 −0 spec/integration/session_spec.rb
View
2  lib/capybara/webkit/driver.rb
@@ -161,7 +161,7 @@ def cookies
end
def invalid_element_errors
- []
+ [Capybara::Webkit::ClickFailed]
end
def version
View
30 spec/integration/session_spec.rb
@@ -336,10 +336,15 @@ module TestSessions
float: left;
margin: 100px;
}
+ #offscreen {
+ position: absolute;
+ left: -5000px;
+ }
</style>
<body>
<div id="one" class="target"></div>
<div id="two" class="target"></div>
+ <div id="offscreen"><a href="/" id="foo">Click Me</a></div>
<script type="text/javascript">
var targets = document.getElementsByClassName('target');
for (var i = 0; i < targets.length; i++) {
@@ -394,5 +399,30 @@ module TestSessions
subject.find(:css, '#one').click
}.should raise_error(Capybara::Webkit::ClickFailed)
end
+
+ it 'raises an error if an element is not in the viewport when clicked' do
+ subject.visit('/')
+ lambda { subject.click_link "Click Me" }.should raise_error(Capybara::Webkit::ClickFailed)
+ end
+
+ context "with wait time of 1 second" do
+ around do |example|
+ default_wait_time = Capybara.default_wait_time
+ Capybara.default_wait_time = 1
+ example.run
+ Capybara.default_wait_time = default_wait_time
+ end
+
+ it "waits for an element to appear in the viewport when clicked" do
+ subject.execute_script <<-JS
+ setTimeout(function() {
+ var offscreen = document.getElementById('offscreen')
+ offscreen.style.left = '10px';
+ }, 400);
+ JS
+
+ lambda { subject.click_link "Click Me" }.should_not raise_error(Capybara::Webkit::ClickFailed)
+ end
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.