画面遷移するまで待つ系の処理で、そのページにしか存在しないテキストでマッチさせるというのがあるんだけれど、それも結構大変なので、そのページにしかない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
いちいちそのページのテキストとマッチさせなくていいので楽〜。