【问题标题】:Poltergeist-phantomjs - switching to the new popped up windowPoltergeist-phantomjs - 切换到新的弹出窗口
【发布时间】:2015-11-05 21:53:08
【问题描述】:

测试环境:Capybara、poltergeist、phantomjs。

当我单击测试用例中的链接时,会打开一个新窗口。我能够切换到新窗口并使用 selenium 驱动程序验证文本。但是,我无法使用 poltergeist 切换到新窗口。我尝试了以下方法切换到新窗口,但都没有奏效。 我想看看一个新的浏览器是否正在打开并且看起来是这样。

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)

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

【问题讨论】:

    标签: ui-automation poltergeist headless-browser


    【解决方案1】:

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

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

    新窗口中嵌入了一个 pdf。当我使用 selenium 驱动程序时,我能够读取并验证文档的内容。使用 poltergeist,我无法阅读 pdf。你能给我一些关于如何进行的指示吗?

    【讨论】:

    • 这个实现正是我想要的。只有我使用了这个post 来让我的代码更有条理
    【解决方案2】:

    Capybara 有许多跨驱动程序方法来处理此问题,而无需转到特定于驱动程序的方法。

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

    【讨论】:

    • 真的很享受,是一个非常优雅的实现
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多