切换到黄瓜,水豚的弹出窗口
在RSpec我可以使用这样的代码切换到弹出窗口, 链接 ,我怎么能在Cucumber步骤中做这样的事情?
login_window = page.driver.find_window('PPA_identity_window') main_window = page.driver.find_window('') # We use this to execute the next instructions in the popup window page.within_window(login_window) do #Normally fill in the form and log in fill_in 'email', :with => "" fill_in 'password', :with => "" click_button 'Log In' end
我不认为有这样做的黄瓜/水豚方式。
但您仍然可以使用selenium驱动程序命令更改窗口,如下所示:
#Get the main window handle main = page.driver.browser.window_handles.first #Get the popup window handle popup = page.driver.browser.window_handles.last #Then switch control between the windows page.driver.browser.switch_to.window(popup)
编辑:安德鲁斯回答下面是正确的答案,因为实施了新的DSL更改。
您可以在Cucumber步骤中使用Capybara与弹出窗口进行交互:
login_window = window_opened_by do click_button 'Open Login Window' end within_window(login_window) do fill_in :email, with: "email@example.com" fill_in :password, with: "password" click_button 'Log In' end
我们可以通过一种简单的方式实现这一目标,无需使用within_window和没有selenium natives。
page.switch_to_window page.windows.first page.switch_to_window page.windows.last
要么
page.switch_to_window page.windows[0] page.switch_to_window page.windows[-1]
0 – 是第一个窗口
-1 – 是最后一个窗口
windows函数返回所有窗口的数组。
另一种方式,使用页面标题。
page.switch_to_window {title ==’Google’}