2015-11-05 54 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