Skip to content
This repository has been archived by the owner on Nov 27, 2020. It is now read-only.

Capybara::Poltergeist::DeadClient when JS errors are thrown #232

Closed
pfleidi opened this issue Jan 10, 2013 · 27 comments
Closed

Capybara::Poltergeist::DeadClient when JS errors are thrown #232

pfleidi opened this issue Jan 10, 2013 · 27 comments

Comments

@pfleidi
Copy link

pfleidi commented Jan 10, 2013

Hello,

Some days ago one of our tests using poltergeist started to fail with Capybara::Poltergeist::DeadClient errors.

Here's the code causing the error:

  within(:css, "form#node-type-form") do
    fill_in("name", :with => content_type)
    fill_in("description", :with => description)
    click_button("edit-submit")
  end

And here's the shell output:

      The PhantomJS client died while processing {"args":[2,3],"name":"click"} (Capybara::Poltergeist::DeadClient)
      (eval):2:in `send'
      (eval):2:in `click_button'
      ./features/step_definitions/content_creation_steps.rb:17
      ./features/step_definitions/content_creation_steps.rb:14:in `/^I create a content type named ["']([^"']+)["'] with description ["']([^"']+)["']$/'
      features/fivestar.feature:24:in `And I create a content type named "fivestar-01" with description "fivestar type"'

My current setup looks like this:

  • Ruby 1.8.7
  • Cucumber (1.2.1)
  • Capybara (1.1.3)
  • Poltergeist (1.0.2)
  • PhantomJS 1.8.1

I am running my tests on OS X 10.8 and Ubuntu 8.04.4 LTS. The js_errors option is set to false:

  options = {
    :js_errors => false,
    :window_size => [1280, 768],
    :debug => true
  }

After debugging the problem a bit more, I found out that a JS error is thrown when loading the site:

{"args"=>["http:/my.site/path"], "name"=>"visit"}
{"error"=>{"args"=>[[{"stack"=>"TypeError: 'undefined' is not an object (evaluating 'jQuery.timeago.settings')\n    at http://my.site/sites/all/modules/timeago/timeago.js?mgexlw:13", "message"=>"TypeError: 'undefined' is not an object (evaluating 'jQuery.timeago.settings')"}]], "name"=>"Poltergeist.JavascriptError"}}
Capybara::Poltergeist::JavascriptError
{"args"=>[".//body[contains(concat(' ', @class, ' '), ' logged-in ')]"], "name"=>"find"}
{"response"=>{"ids"=>[0], "page_id"=>1}}

After fixing the JS error, the test started working again. So the crash is probably caused by the uncaught error.

I also created a a crashdump of phantomJS.

It currently looks like phantomJS dies after encountering a JS error when js_error is set to false.

@jonleighton
Copy link
Contributor

Do you get the error on the Ubuntu machine? If so please could you create a crash dump from there?

@pfleidi
Copy link
Author

pfleidi commented Jan 11, 2013

@jonleighton: Yes, a similar error occurred on the Ubuntu machine. Here's the crash report.

@jonleighton
Copy link
Contributor

Can you try current master? js_errors: false was pretty broken before today.

@enricostano
Copy link

Same problem here on ArchLinux and :js_errors => false

{"name"=>"find", "args"=>[".//input[@id = 'submit']"]}
{"response"=>{"page_id"=>2, "ids"=>[2]}}
{"name"=>"click", "args"=>[2, 2]}
poltergeist [1363177956214] state default -> clicked
poltergeist [1363177956226] state clicked -> loading
PhantomJS has crashed. Please read the crash reporting guide at https://github.com/ariya/phantomjs/wiki/Crash-Reporting and file a bug report at https://code.google.com/p/phantomjs/issues/entry with the crash dump file attached: /tmp/7847aeeb-48ea-0700-2d748465-3f4a658d.dmp
{"name"=>"set_debug", "args"=>[true]}

The weird thing is that if I pause the test just before "hitting" the submit input waiting like a couple of seconds and then going ahead it works...

@olivierlacan
Copy link
Contributor

@enricostano Still having this issue on ArchLinux? Having it on Ubuntu.

@enricostano
Copy link

sorry @olivierlacan , I gave up on this. Not using Poltergeist anymore. 😞

@olivierlacan
Copy link
Contributor

Ditto. I don't blame Poltergeist to be fair. I blame PhantomJS.

@pixelpax
Copy link

This is frustrating. I'm having the same problem and I'm using PhantomJS 1.9.8

How do they not have this fixed?

What are you guys using instead now?

@constantm
Copy link

We're still getting this randomly on tests running on Semaphore. Not happening on local OSX dev machines.

@mois3x
Copy link

mois3x commented Sep 20, 2015

This is weird... still happening randomly when it is used on Rails 3, On rails 4 its ok.

@twalpole
Copy link
Contributor

Can anyone provide a minimal example that reproduces the issue? Without that it's pretty hard to fix

@twalpole
Copy link
Contributor

twalpole commented Jan 4, 2016

Closing this due to age, lack of details usable for debugging and the appearance of it most likely being an issue with older phantomjs -- If anyone has a reproducible test case using latest versions of poltergeist/phantomjs please open a new issue

@twalpole twalpole closed this as completed Jan 4, 2016
@caseyprovost
Copy link

@twalpole I am seeing this issue still, hard to track down.

phantomjs 2.1.1
poltergeist (1.9.0)
capybara (2.5.0)

If you need more information I am happy to collaborate and send whatever you need to track this down.

@twalpole
Copy link
Contributor

@caseyprovost - What we really need is a reproducible minimal test case

@Azrasyed
Copy link

Azrasyed commented Apr 6, 2016

@twalpole I'm facing the same issue. I'm trying to run my tests on Jenkins.

Scenario: Adding item to cart and checkout # features/web_checkout.feature:4
Given I am on the homepage # features/step_definitions/web_steps.rb:12
And I submit the registration portal with valid credentials # features/step_definitions/signup.rb:1
Account successfully created
PhantomJS has crashed. Please read the bug reporting guide at
http://phantomjs.org/bug-reporting.html and file a bug report.
And I submit the password portal with valid credentials # features/step_definitions/signup.rb:21
PhantomJS client died while processing {"id":"5b507f23-6bf4-409b-8a68-5fed2edcaa2b","name":"body","args":[]} (Capybara::Poltergeist::DeadClient)

@twalpole
Copy link
Contributor

twalpole commented Apr 7, 2016

@Azrasyed As stated before -- what we need is a reproducible test case using phantomjs 2.1.1+ -- without that there really is no way for us to figure out whats going on.

@cmthakur
Copy link

@jonleighton @twalpole I'm facing the same issue. I'm trying to run my tests on Jenkins.
My scenarios are same as @Azrasyed, and Gemfile looks like this.

phantomjs (2.1.1.0)
poltergeist (1.9.0)
      capybara (~> 2.1)
      cliver (~> 0.3.1)
      multi_json (~> 1.0)
      websocket-driver (>= 0.2.0)

Error looks like this:

Capybara::Poltergeist::DeadClient:
       PhantomJS client died while processing {"id":"5d43dca7-add2-4280-8192-2ae0cadc15d5","name":"visit","args":["http://localhost:9887/admin/likeman/246/edit",90]}
      # /var/bundle/ruby/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/server.rb:38:in `send'
     # /var/bundle/ruby/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:344:in `command'
     # /var/bundle/ruby/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/browser.rb:34:in `visit'
     # /var/bundle/ruby/2.3.0/gems/poltergeist-1.9.0/lib/capybara/poltergeist/driver.rb:95:in `visit'

@volkanunsal
Copy link

I came across this issue as well. Here is the dump file of the error.

@cmthakur
Copy link

@jonleighton @twalpole The issue resolved by increasing poltergeist timeout value.

  options = {
              js_errors: false,
              extensions: [],
              phantomjs_options:['--proxy-type=none', '--load-images=no', '--ignore-ssl-errors=true'],
              timeout: 180,
              window_size: ['1300', '1800'],
              inspector: true,
            }

@volkanunsal
Copy link

@cmthakur My timeout is 1000 and still seeing this issue.

@constantm
Copy link

constantm commented May 16, 2016

We've done the following and it seems to have helped tremendously with random errors and memory use when running tests:

# spec/spec_helper.rb
config.after :each do |example|
  page.driver.restart if defined?(page.driver.restart)
end

This resets PhantomJS completely after each test and has no noticeable performance impact.

@cmthakur
Copy link

@jonleighton @twalpole can you try this in spec_helper.rb, it works for me.

   config.after(:each) do
      Capybara.reset_sessions!
      DatabaseCleaner.clean
   end

In capybara.rb

Capybara.register_driver :poltergeist_debug do |app|
  options = {
              js_errors: false,
              extensions: [],
              phantomjs_options:['--proxy-type=none', '--load-images=no', '--ignore-ssl-errors=true'],
              timeout: 180,
              window_size: ['1300', '1800'],
              inspector: true,
            }
  Capybara::Poltergeist::Driver.new(app, options)

@justin808
Copy link

It seems like the key thing is that js_errors: false.

I get crashes otherwise in #830.

@bradens
Copy link

bradens commented Mar 15, 2017

Oh my god @constantm you helped me a lot with the trick to restart the driver after each test..been battling unreliable phantomjs crashes for weeks! cheers!

@dxypher
Copy link

dxypher commented Mar 27, 2017

Still happening in CircleCI.
Already had js_errors: false, and tried @constantm solution...but no luck.

Difficult to provide steps to reproduce as it happens intermittently and the specs that fail aren't always the same ones.

Update:

Noticed similar issue back in 2012...related to people who'd upgraded to a newer version of Bootstrap.

I also started seeing this issue when I upgraded to Bootstrap 4 alpha-6

@MatzFan
Copy link

MatzFan commented Nov 11, 2017

Restarting the driver, as per @constantm fixed the problem for me (which was caused by forking in my code) but there was a performance hit: ~0.19s on my machine.

@srish
Copy link

srish commented Apr 28, 2018

In my case only some test cases were problematic, and so it wasn't necessary to include the changes in the spec_helper.rb to driver restart after every test case. Building on @constantm's solution, adding the snippet within a context block worked:

context 'user logged in' do
    before(:each) do
        page.driver.restart if defined?(page.driver.restart)
    end
end

arvados-bot pushed a commit to arvados/arvados that referenced this issue Jun 5, 2018
Shot in the dark from teampoltergeist/poltergeist#232

Arvados-DCO-1.1-Signed-off-by: Tom Clegg <tclegg@veritasgenetics.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests