2015-11-05 53 views
2

测试环境:水豚,poltergeist,phantomjs。Poltergeist-phantomjs - 切换到新弹出窗口

当我点击测试用例中的链接时,会打开一个新窗口。我能够切换到新窗口并使用硒驱动程序验证文本。但是,我无法用怪物转向新窗口。我试着用下面的方法切换到新窗口,但都没有工作。 我想看看一个新的浏览器是否开放,看起来是这样。

main = page.driver.browser.window_handles.first 
     puts main (gives 0) 
     popup = page.driver.browser.window_handles.last 
     puts popup (gives 1) 

    1. within_window(->{ page.title == '2015-11-5.pdf' }) { assert_text(facility_name) } 
    2. page.switch_to_window(window=popup) 
    3. page.switch_to_window(page.driver.browser.window_handles.last) 
    4. page.driver.browser.switch_to().window(page.driver.browser.window_handles.last) 

有人可以在这里提供任何输入吗?谢谢!

回答

1

水豚有很多交叉驱动方法来处理这个问题,而不必去驱动程序的具体方法。

popup = page.window_opened_by { 
    click_link('whatever link opens the new window') 
} 
within_window(popup) do 
# perform actions in the new window 
end 
+0

真的很享受,做个非常优雅的实现 – jonathanccalixto

2

我使用了下面的内容,弹出窗口正在生成,控件切换到它。

page.switch_to_window(page.window_opened_by{click_link('Generate Report')}) 

新的窗口有嵌入它。我能够读取和验证文档的内容,当我使用硒驱动程序的PDF文件。与poltergeist,我无法阅读PDF。你能给我一些关于如何进行的指导吗?

+0

这个实现就是我想要的。只有我使用这[后](http://stackoverflow.com/questions/33555502/poltergeist-phantomjs-switching-to-the-new-popped-up-window#answer-33557805)变得更有组织我的代码 – jonathanccalixto