mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Wait and timeout when looking for content
This commit is contained in:
parent
eeabaf506f
commit
40804c06ba
3 changed files with 49 additions and 3 deletions
|
@ -61,7 +61,7 @@ class Capybara::Driver::Webkit
|
|||
end
|
||||
|
||||
def wait?
|
||||
false
|
||||
true
|
||||
end
|
||||
|
||||
def wait_until(*args)
|
||||
|
|
|
@ -2,11 +2,54 @@ require 'spec_helper'
|
|||
require 'capybara-webkit'
|
||||
|
||||
describe Capybara::Session do
|
||||
subject { Capybara::Session.new(:reusable_webkit, @app) }
|
||||
after { subject.reset! }
|
||||
|
||||
context "slow javascript app" do
|
||||
before(:all) do
|
||||
@app = lambda do |env|
|
||||
body = <<-HTML
|
||||
<html><body>
|
||||
<form action="/next" id="submit_me"><input type="submit" value="Submit" /></form>
|
||||
<p id="change_me">Hello</p>
|
||||
|
||||
<script type="text/javascript">
|
||||
var form = document.getElementById('submit_me');
|
||||
form.addEventListener("submit", function (event) {
|
||||
event.preventDefault();
|
||||
setTimeout(function () {
|
||||
document.getElementById("change_me").innerHTML = 'Good' + 'bye';
|
||||
}, 500);
|
||||
});
|
||||
</script>
|
||||
</body></html>
|
||||
HTML
|
||||
[200,
|
||||
{ 'Content-Type' => 'text/html', 'Content-Length' => body.length.to_s },
|
||||
[body]]
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
@default_wait_time = Capybara.default_wait_time
|
||||
Capybara.default_wait_time = 1
|
||||
end
|
||||
|
||||
after { Capybara.default_wait_time = @default_wait_time }
|
||||
|
||||
it "waits for a request to load" do
|
||||
subject.visit("/")
|
||||
subject.find_button("Submit").click
|
||||
subject.should have_content("Goodbye");
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe Capybara::Session, "with TestApp" do
|
||||
before do
|
||||
@session = Capybara::Session.new(:webkit, TestApp)
|
||||
@session = Capybara::Session.new(:reusable_webkit, TestApp)
|
||||
end
|
||||
|
||||
# TODO: needs to only use one Browser throughout tests
|
||||
# it_should_behave_like "session"
|
||||
# it_should_behave_like "session with javascript support"
|
||||
end
|
||||
|
|
|
@ -20,3 +20,6 @@ require File.join(spec_dir,"spec_helper")
|
|||
require 'capybara/driver/webkit/browser'
|
||||
$webkit_browser = Capybara::Driver::Webkit::Browser.new(:socket_class => TCPSocket)
|
||||
|
||||
Capybara.register_driver :reusable_webkit do |app|
|
||||
Capybara::Driver::Webkit.new(app, :browser => $webkit_browser)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue