Return to the first window after yield

This commit is contained in:
Matthew Horan 2012-03-27 13:14:01 -04:00
parent 7149ec7a39
commit 468bec886f
5 changed files with 29 additions and 9 deletions

View File

@ -82,7 +82,11 @@ class Capybara::Driver::Webkit
end
def window_focus(handle=nil)
command("WindowFocus")
if handle
command("WindowFocus", handle)
else
command("WindowFocus")
end
end
def command(name, *args)

View File

@ -1560,6 +1560,7 @@ describe Capybara::Driver::Webkit do
<script type="text/javascript">
window.open('http://#{request.host_with_port}/test?#{request.query_string}');
</script>
<p>bananas</p>
</html>
HTML
else
@ -1575,16 +1576,22 @@ describe Capybara::Driver::Webkit do
it "has the expected text in the new window" do
subject.visit("/new_window")
subject.within_window(nil) do
subject.within_window(true) do
subject.find("//p").first.text.should == "finished"
end
end
it "waits for the new window to load" do
subject.visit("/new_window?sleep=1")
subject.within_window(nil) do
subject.within_window(true) do
lambda { Timeout::timeout(1) { subject.find("//p") } }.should_not raise_error(Timeout::Error)
end
end
it "switches back to the original window" do
subject.visit("/new_window")
subject.within_window(true) { }
subject.find("//p").first.text.should == "bananas"
end
end
end

View File

@ -17,6 +17,10 @@ void WebPageManager::append(WebPage *value) {
webPages->append(value);
}
WebPage *WebPageManager::first() {
return (WebPage*) webPages->first();
}
WebPage *WebPageManager::last() {
return (WebPage*) webPages->last();
}

View File

@ -5,6 +5,7 @@ class WebPageManager {
public:
static WebPageManager *getInstance();
void append(WebPage *value);
WebPage *first();
WebPage *last();
private:

View File

@ -7,12 +7,16 @@ WindowFocus::WindowFocus(WebPage *page, QStringList &arguments, QObject *parent)
}
void WindowFocus::start() {
WebPage *webPage = WebPageManager::getInstance()->last();
if (webPage) {
emit windowChanged(webPage);
success();
} else {
windowNotFound();
WebPageManager *manager = WebPageManager::getInstance();
switch(arguments().length()) {
case 1:
emit windowChanged(manager->last());
success();
break;
default:
emit windowChanged(manager->first());
success();
}
}