<-- home

Capybara 测试新打开 window

在测试中,遇到新打开一个 window 的情况,例如 target=”_blank”,如果直接检测页面元素,会发现始终检测不到
这是因为 capybara 并不知道切换 window,这时候要使用

Then /^I click on the "([^"]*)" link with new window and see "([^"]*)"$/ do |link, message|
  new_window = window_opened_by { click_link link }

  within_window new_window do
    expect(page).to have_content message
  end
end