Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Switch to popup windows in cucumber, capybara

In RSpec i can use such code switch to popup window, link, How can i do such thing in Cucumber steps?

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
like image 387
Aydar Omurbekov Avatar asked Sep 24 '13 13:09

Aydar Omurbekov


2 Answers

You can use Capybara in your Cucumber steps to interact with popup windows:

login_window = window_opened_by do
  click_button 'Open Login Window'
end
within_window(login_window) do
  fill_in :email, with: "[email protected]"
  fill_in :password, with: "password"
  click_button 'Log In'
end
like image 83
Andrew Avatar answered Oct 08 '22 10:10

Andrew


I don't think there is a cucumber/capybara way to do this as such.

But you can still change the window using selenium driver commands like this:

    #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)

EDIT: Andrews answer below is the correct answer now since new DSL changes were implemented.

like image 15
snowstreams Avatar answered Oct 08 '22 11:10

snowstreams