New Tabs and Cucumber
While working on an internal app at GitHub I had to write a cucumber scenario that ran expectations against a new tab that was opened. Here is how I did it.
Searching around the internet, I finally found a tip on StackOverflow that got me moving in the right direction. In this context tabs are referred to as windows.
This code grabs the browser object and calls switch_to window on it and passes in the last opened window.
Now all we need to do is wrap this in a step so we can use it in our scenarios.
When /^I access the new tab$/ do page.driver.browser.switch_to.window(page.driver.browser.window_handles.last) end
This will only work if you are using selenium-webdriver. It will not work with capybara-webkit unfortunately. So I switched to selenium, but I told it to use chrome instead of the default firefox and it still works great!
The link that I follow opens the new page in a new tab, I select the new tab, then run my expectations against it.