capybara window management
# Capybara::Window
See also:
# Example
window_opened_by
method with block passed that contains the action that will open a new browser window.within_window
the switch to a window context to run expections
1: new_window = window_opened_by { click_link 'will open a new window' } 2: within_window new_window do 3: expect(page).to have_current_path '/new/window/url' 4: end
# Dealing with alerts with Selenium
See also:
- https://github.com/SeleniumHQ/selenium/wiki/Ruby-Bindings#javascript-dialogs
- https://stackoverflow.com/a/26888469/5974855
- https://devhints.io/capybara
alert = page.driver.browser.switch_to.alert
expect(alert.text).to eq 'foo'