mirror of
https://github.com/thoughtbot/capybara-webkit
synced 2023-03-27 23:22:28 -04:00
Ensure pending commands will block until the new window is loaded
This commit is contained in:
parent
efa577c3f0
commit
7149ec7a39
2 changed files with 14 additions and 2 deletions
|
@ -1553,15 +1553,18 @@ describe Capybara::Driver::Webkit do
|
||||||
context "javascript new window app" do
|
context "javascript new window app" do
|
||||||
before(:all) do
|
before(:all) do
|
||||||
@app = lambda do |env|
|
@app = lambda do |env|
|
||||||
if env['PATH_INFO'] == '/new_window'
|
request = ::Rack::Request.new(env)
|
||||||
|
if request.path == '/new_window'
|
||||||
body = <<-HTML
|
body = <<-HTML
|
||||||
<html>
|
<html>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.open('http://#{env['HTTP_HOST']}/test');
|
window.open('http://#{request.host_with_port}/test?#{request.query_string}');
|
||||||
</script>
|
</script>
|
||||||
</html>
|
</html>
|
||||||
HTML
|
HTML
|
||||||
else
|
else
|
||||||
|
params = request.params
|
||||||
|
sleep params['sleep'].to_i if params['sleep']
|
||||||
body = "<html><p>finished</p></html>"
|
body = "<html><p>finished</p></html>"
|
||||||
end
|
end
|
||||||
[200,
|
[200,
|
||||||
|
@ -1576,5 +1579,12 @@ describe Capybara::Driver::Webkit do
|
||||||
subject.find("//p").first.text.should == "finished"
|
subject.find("//p").first.text.should == "finished"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "waits for the new window to load" do
|
||||||
|
subject.visit("/new_window?sleep=1")
|
||||||
|
subject.within_window(nil) do
|
||||||
|
lambda { Timeout::timeout(1) { subject.find("//p") } }.should_not raise_error(Timeout::Error)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -72,6 +72,8 @@ void Connection::writeResponse(Response *response) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connection::changeWindow(WebPage *newPage) {
|
void Connection::changeWindow(WebPage *newPage) {
|
||||||
|
disconnect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
||||||
m_page = newPage;
|
m_page = newPage;
|
||||||
|
connect(m_page, SIGNAL(pageFinished(bool)), this, SLOT(pendingLoadFinished(bool)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue