LoginSignup
31
26

More than 5 years have passed since last update.

Capybaraでsleep地獄から抜け出すための便利なメソッド

Posted at

capybaraでajax周りのテストを実装する際に、よくsleep(秒数)を使って実装していたが、無駄な秒数が多かったり、そもそも設定した秒数だと足りずに結局エラーになったりと安定しなかったので色々調べていると、"until"を使うと要素が見つかるまで待たせる事ができるらしい。

これでsleepに悩まされない!!と思い、早速以下のようなメソッドを作った。

ajax_helper.rb

  def wait_for_loaded_until_css_exists(selector)
    until has_css?(selector); end
  end

  def wait_for_loaded_until_content_exists(content)
    until has_content?(content); end
  end

これで無駄無くテストが実行できる(`・ω・´)キリッ

31
26
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
31
26