Skip to content

Instantly share code, notes, and snippets.

@kkganesan
Created December 17, 2011 16:00
Show Gist options
  • Save kkganesan/1490592 to your computer and use it in GitHub Desktop.
Save kkganesan/1490592 to your computer and use it in GitHub Desktop.
Navigation to new window using capybara/selenium gives blank page
Feature: Demo
Yahoo authentication
@user_login
Scenario: logging in as user
Given I am in "http://mail.yahoo.com"
Then I should see "Sign in to Yahoo!"
And I fill in userid with "YOUR_USERID" and password "YOUR_PASSWORD"
And I press "Sign In"
Then I should be logged in and find "INBOX"
@mail_home
Scenario: Navigate to Yahoo home page
When I click on "Yahoo!"
Then I should see "Mobile" in a new window
steps_for :user_login do
step "I am in :url" do |url|
visit url
end
step "I fill in userid with :userid and password :password" do |userid,password|
page.fill_in('login', :with => userid)
page.fill_in('passwd', :with => password)
end
step "I press :signin" do |signin|
page.click_button(signin)
end
step "I should be logged in and find :inbox" do |inbox|
page.find_link(inbox)
end
end
steps_for :mail_home do
use_steps :user_login
step "I click on :yahoo" do |yahoo|
page.driver.browser.window_handles.length.should == 1
page.click_link(yahoo)
page.driver.browser.window_handles.length.should == 2
end
step "I should see :mobile in a new window" do |mobile|
page.driver.browser.switch_to.window(page.driver.browser.window_handles[1])
page.should have_content(mobile)
end
end
@kkganesan
Copy link
Author

Test only works if @browser.navigate.to('about:blank') was commented in the reset method of Capybara's driver.rb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment