LoginSignup
3
1

More than 5 years have passed since last update.

capybaraとpoltergeistで別ウィンドウで開いたページのテストを行う

Posted at

たとえばリンクをクリックして別ウィンドウで開いたページの内容が正しいかテストする場合

sample_steps.rb
  step 'テスト画面が別Windowで表示されていること' do
    # 1
    handle = page.driver.browser.window_handles.last
    # 2
    page.driver.browser.within_window(handle) do
      # 3
      expect(page).to have_content('あいうえお')
    end  
  end

たぶんこんな感じ。
1.最後にブラウザで開いたハンドルを取得
2.そのハンドルからブラウザページを取得
3.pageの内容は、開かれたページの内容

参考

CapybaraのPoltergeistを使ったテストでブラウザの別のタブに移動する

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1