Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby on Rails: Cucumber: how do I follow a link that opens a new window?

I have a link that opens in a new window, and I need to test the part of my app that is within that new window.

Any suggestions will be much appreciated.

like image 317
NullVoxPopuli Avatar asked Jun 23 '10 18:06

NullVoxPopuli


2 Answers

Define a step that contains this code:

page.driver.browser.switch_to.window (page.driver.browser.window_handles.last)

switch_to is a selenium command that allows you to change over to a new window window_handles returns a list of currently open windows

like image 54
Tian Avatar answered Nov 15 '22 06:11

Tian


I realize this is a very old post, but here's a Cucumber step definition using Capybara and the Poltergeist driver:

And /^I follow "([^"]*)" to the new window$/ do |link|
  new_window = window_opened_by { click_link link }
  switch_to_window new_window
end
like image 25
MothOnMars Avatar answered Nov 15 '22 07:11

MothOnMars