切换到黄瓜,水豚的弹出窗口

Ayd*_*kov 8 ruby popupwindow capybara

在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 => "<your paypal sandbox username>"
      fill_in 'password', :with => "<your paypal sandbox password>"
      click_button 'Log In'
    end
Run Code Online (Sandbox Code Playgroud)

And*_*rew 24

您可以在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
Run Code Online (Sandbox Code Playgroud)


sno*_*ams 15

我不认为有这样的黄瓜/水豚方式.

但您仍然可以使用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)
Run Code Online (Sandbox Code Playgroud)

编辑:安德鲁斯回答下面是正确的答案,因为实施了新的DSL更改.

  • Capybara现在提供了一个用于与弹出窗口交互的DSL.请参阅下面的答案. (2认同)