LoginSignup
2
1

More than 5 years have passed since last update.

Capybaraで要素があるまで待つ(ページ遷移対策)

Posted at

画面遷移するまで待つ系の処理で、そのページにしか存在しないテキストでマッチさせるというのがあるんだけれど、それも結構大変なので、そのページにしかないidなりclassなりで検証したいなーと思ったので定義した。

spec/support/wait_until_element_exists.rb
module WaitUntilElementExists
  def wait_until_element_exists(selector)
    Timeout.timeout(Capybara.default_max_wait_time) do
      loop until page.all(selector).present?
    end
  end
end

RSpec.configure do |config|
  config.include WaitUntilElementExists, type: :feature
end

いちいちそのページのテキストとマッチさせなくていいので楽〜。

2
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
2
1