twalpole / apparition

Capybara driver for Chrome using CDP
MIT License
363 stars 46 forks source link

Be able to increase timeout in wait_for_loaded #14

Closed dentarg closed 5 years ago

dentarg commented 5 years ago

Hi, thanks for a great gem!

Would it be possible to make the expire_in value sent to Capybara::Helpers.timer in wait_for_loaded configurable?

https://github.com/twalpole/apparition/blob/3dddbbd5e66fde2186ff3b53612dbe55a6149bba/lib/capybara/apparition/page.rb#L232-L233

The README says that it is possible to use :timeout (and that default is 30 seconds), but I was consistently getting the error below until I went into the apparition directory in ~/.gem/ and raised expire_in. I could also see that my test never ran for 30 seconds, it was always somewhere around 15 seconds.

Failures:

  1)
     Failure/Error: visit(URL)

     Capybara::Apparition::StatusFailError:
       Request to '<URL>' failed to reach server, check DNS and/or server status
     # /Users/dentarg/.gem/ruby/2.6.2/gems/apparition-0.1.0/lib/capybara/apparition/page.rb:269:in `rescue in visit'
     # /Users/dentarg/.gem/ruby/2.6.2/gems/apparition-0.1.0/lib/capybara/apparition/page.rb:257:in `visit'
     # /Users/dentarg/.gem/ruby/2.6.2/gems/apparition-0.1.0/lib/capybara/apparition/driver.rb:91:in `visit'
     # /Users/dentarg/.gem/ruby/2.6.2/gems/capybara-3.16.1/lib/capybara/session.rb:277:in `visit'
     # /Users/dentarg/.gem/ruby/2.6.2/gems/capybara-3.16.1/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
     # ./scrape.rb:109:in `block (2 levels) in <top (required)>'
     # ------------------
     # --- Caused by: ---
     # Capybara::Apparition::TimeoutError:
     #   Timed out waiting for response to wait_for_loaded. It's possible that this happened because something took a very long time (for example a page load was slow). If so, setting the Apparition :timeout option to a higher value will help (see the docs for details). If increasing the timeout does not help, this is probably a bug in Apparition - please report it to the issue tracker.
     #   /Users/dentarg/.gem/ruby/2.6.2/gems/apparition-0.1.0/lib/capybara/apparition/page.rb:238:in `wait_for_loaded'

(I'm loading a page from the internet, not an app running locally, so that's why I would like to give everything some more time.)

twalpole commented 5 years ago

Sure -- I can't get to this right now, but PRs are welcome - or I can probably look at it over the weekend.

dentarg commented 5 years ago

@twalpole do you have any opinions/ideas on how to solve it? should we use the :timeout value instead of the hardcoded value?

twalpole commented 5 years ago

@dentarg Yeah - using the timeout value probably makes the most sense.

twalpole commented 5 years ago

@dentarg Sorry - this has taken me longer than expected to get around to. As a temporary fix I've changed this to 30 seconds and pushed it to master. Hopefully I'll get to making it configurable sometime in the next week.

twalpole commented 5 years ago

This has been delayed as I've been working on reworking a lot of things to cleanup and simplify the code.