percy / percy-capybara

Visual testing for Capybara with Percy.
https://docs.percy.io/docs/capybara
MIT License
45 stars 23 forks source link

PercyAgent not defined #143

Closed joekur closed 4 years ago

joekur commented 4 years ago

I'm seeing some intermittent issues when using selenium / headless chrome / percy-capybara / rspec / CircleCI. Error output:

[percy] Snapshotting failed. Note that Poltergeist and Rake::Test are no longer supported by percy-capybara. Error: javascript error: PercyAgent is not defined

We are running via npx percy exec -- rspec

Any idea how this might happen, or how to better track down the root issue? It's pretty consistently one particular spec.

Robdel12 commented 4 years ago

Hey @joekur, thanks for the issue! Does that spec have JS enabled? Or which driver is it using?

joekur commented 4 years ago

Yes js is enabled, using selenium headless chrome.

Edit - for clarity most specs are snapshotting just fine (same js enabled / selenium headless chrome).

Robdel12 commented 4 years ago

Gotcha, good to know. It's nice that it's a single test that fails consistently. This is what is failing: https://github.com/percy/percy-capybara/blob/master/lib/percy.rb#L83-L92 Which means the JS was never ran on the page: https://github.com/percy/percy-capybara/blob/master/lib/percy.rb#L65-L72

Does this test happen to have any VCR/network mocking going on?

joekur commented 4 years ago

@Robdel12 yes there is plenty of network mocking going on. I'm not seeing the Could not load... error in the logs like the Snapshotting failed.. one I do see. So I wonder if the error would be in the js execute? https://github.com/percy/percy-capybara/blob/master/lib/percy.rb#L84

joekur commented 4 years ago

I did some monkeypatching to ensure I could see what was being returned by that JS fetch, and confirmed I received window.PercyAgent=function(e){..., before seeing the snapshot failure PercyAgent is not defined

joekur commented 4 years ago

@Robdel12 thank you for your help! I have found that this is happening because there is a race condition of redirection to a new url in this spec. I believe we injecting the percy agent, the page location changes (with window.PercyAgent no longer defined), and then we try to take a snapshot and fail. Consider this a user error 😃