rubycdp / cuprite

Headless Chrome/Chromium driver for Capybara
https://cuprite.rubycdp.com
MIT License
1.25k stars 92 forks source link

Capybara.default_max_wait_time not always respected #122

Open betelgeuse opened 4 years ago

betelgeuse commented 4 years ago

Actual output

     Failure/Error: expect(page).to have_css 'a', text: 'Link Name', visible: :all

     Ferrum::NodeNotFoundError:
       Could not find node with given id

My investigation shows that this code sometimes only waits for around one second and does six retries with the defaults that can be found here:

https://github.com/rubycdp/ferrum/blob/e02b2399dacdcca36f0347832d0580eaee1ee0ed/lib/ferrum/frame/runtime.rb#L8

Expected

Whenever Ferrum::NodeNotFoundError starts bubbling we should retry for the full configured Capybara wait time.

sfcgeorge commented 4 years ago

Ooh I think this is it.

We'd been having the Could not find node with given id bug and in the end increasing the timeout fixed it.

But we're getting that error again on some tests. It's started since switching to a remote chrome (with URL) so I'm guessing there's a slight extra lag there.

Specifically the issue occurs when navigating from one page to another, in our case after an AJAX success but not sure that's relevant. I assume while Chrome is still loading the page there are no elements for Ferrum to find. Perhaps Ferrum could be smarter about navigation and detect while a page is still being fetched.

As a workaround I increased these ENV vars and that's fixed the error:

Old default:

FERRUM_INTERMITTENT_SLEEP=0.1
FERRUM_INTERMITTENT_ATTEMPTS=6

New: ⭐

FERRUM_INTERMITTENT_SLEEP=0.2
FERRUM_INTERMITTENT_ATTEMPTS=24