I'm using Cucumber to run tests and I use both PhantomJS (poltergeist) and Selenium WebDriver. One of my tests is following a redirect to a new window from a hyperlink.
Is there a way that I can write into my step definition for navigating to a window to say: If using Poltergeist, run this line of code else run this one (Selenium as default)?:
Example:
When in Selenium Browser:
within_window(->{ page.title == 'Title' }) do
expect(current_url).to eq('URL')
page.driver.browser.close
end
When in Poltergeist:
new_window = window_opened_by { click_link 'Something' }
within_window new_window do
# code
end
You can base your conditional on the value of Capybara.current_driver
if Capybara.current_driver == :selenium
do the selenium things
else
do the poltergeist things
end