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

page.body returning an integer string #957

Closed
lukegrecki opened this issue Oct 14, 2016 · 5 comments
Closed

page.body returning an integer string #957

lukegrecki opened this issue Oct 14, 2016 · 5 comments

Comments

@lukegrecki
Copy link

I am currently using capybara-webkit (1.11.1) with puffing_billy (0.8.0) to make mock requests from javascript, and am intermittently running into the following error:

Failures:

  1) Analytics Dashboard when the user visits analytics dashboard today's summary details are visible
     Failure/Error: expect(page).to have_link('Summary View')

     Capybara::Webkit::NodeNotAttachedError:
       Element at Summary View no longer present in the DOM
     # /usr/local/bundle/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:305:in `check'
     # /usr/local/bundle/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:211:in `command'
     # /usr/local/bundle/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:31:in `find_xpath'
     # /usr/local/bundle/gems/capybara-webkit-1.11.1/lib/capybara/webkit/driver.rb:55:in `find_xpath'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/node/base.rb:108:in `find_xpath'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/queries/selector_query.rb:112:in `block in resolve_for'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/node/base.rb:81:in `synchronize'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/queries/selector_query.rb:108:in `resolve_for'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/node/matchers.rb:125:in `block in assert_selector'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/node/base.rb:85:in `synchronize'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/node/matchers.rb:124:in `assert_selector'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/session.rb:699:in `block (2 levels) in <class:Session>'
     # /usr/local/bundle/gems/capybara-2.7.1/lib/capybara/rspec/matchers.rb:24:in `matches?'
     # ./spec/features/analytics/dashboard_integration_spec.rb:267:in `block (3 levels) in <top (required)>'
     # ./spec/ui_spec_helper.rb:53:in `block (2 levels) in <top (required)>'

When I added a puts page.body or tried save_and_open_page I found that page.body was returning an integer string such as "5". When I look at the screenshot generated from the failure it shows the page mostly rendered with data from the mock request (including the link Summary View that the assertion is on).

I occasionally get another error:

1) Analytics Dashboard when the user visits analytics dashboard today's summary details are visible
     Failure/Error: p page.body

     JSON::ParserError:
       A JSON text must at least contain two octets!
     # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/errors.rb:31:in `initialize'
     # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:305:in `new'
     # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:305:in `check'
     # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:211:in `command'
     # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:43:in `body'
     # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/driver.rb:68:in `html'
     # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-2.7.1/lib/capybara/session.rb:153:in `html'
     # ./spec/features/analytics/dashboard_integration_spec.rb:269:in `block (3 levels) in <top (required)>'
     # ./spec/ui_spec_helper.rb:53:in `block (2 levels) in <top (required)>'

Any help or direction to fix this would be greatly appreciated.

@lukegrecki
Copy link
Author

I think I narrowed it down further to some interaction with evaluate_script. I'm using this method to wait for react components to get their data from the puffing_billy proxy:

def finished_loading_component_data?
    return_value = page.evaluate_script <<-SCRIPT.strip_heredoc
      (function () {
        return document.querySelectorAll('.wait-for-data--pending').length;
      })()
    SCRIPT
    return_value && return_value.zero?
  end

Is this method kind of unstable? Is there a better way to do this?

@twalpole
Copy link
Collaborator

@lukegrecki Rather than using execute_script that method should just be written as page.has_no_css? '.wait-for-data--pending', visible: :all or `expect(page).to have_no_css('.wait-for-data--pending', visible: :all)' depending whether you want a Boolean result or assertion if it doesn't become true within Capybara.default_max_wait_time seconds. Whether or not that will fix your issue I have no idea.

@lukegrecki
Copy link
Author

@twalpole Thanks! That seemed to be the cause of the the broken pipe errors I was seeing earlier and I also don't think I've seen the errors I mentioned above since. I am experimenting with waiting for all the css data elements I want to do assertions on instead of depending on '.wait-for-data--pending'.

@lukegrecki
Copy link
Author

lukegrecki commented Oct 17, 2016

Nevermind, I'm still basically where I started. There was a set of requests I was ignoring with puffing-billy but after mocking them I'm consistently getting a broken pipe error:

1) Analytics Dashboard when the user visits analytics dashboard today's summary details are visible
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: visit analytics_dashboard_path

          EOFError:
            end of file reached
          # <internal:prelude>:76:in `__read_nonblock'
          # <internal:prelude>:76:in `read_nonblock'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/connection.rb:41:in `read'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/connection.rb:32:in `gets'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:299:in `check'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:211:in `command'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:19:in `visit'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/driver.rb:50:in `visit'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-2.7.1/lib/capybara/session.rb:233:in `visit'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-2.7.1/lib/capybara/dsl.rb:52:in `block (2 levels) in <module:DSL>'
          # ./spec/features/analytics/dashboard_integration_spec.rb:139:in `load_analytics_dashboard'
          # ./spec/features/analytics/dashboard_integration_spec.rb:276:in `block (3 levels) in <top (required)>'
          # ./spec/ui_spec_helper.rb:53:in `block (2 levels) in <top (required)>'

     1.2) Failure/Error: example.run

          Capybara::Webkit::CrashError:
            The webkit_server process crashed!

              Connection reset by peer

            This is a bug in capybara-webkit. For help with this crash, please visit:

            https://github.com/thoughtbot/capybara-webkit/wiki/Reporting-Crashes
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:215:in `rescue in command'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:205:in `command'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/browser.rb:79:in `current_url'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-webkit-1.11.1/lib/capybara/webkit/driver.rb:46:in `current_url'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-2.7.1/lib/capybara/session.rb:181:in `current_url'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-screenshot-1.0.13/lib/capybara-screenshot/rspec.rb:55:in `block in after_failed_example'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-2.7.1/lib/capybara.rb:352:in `using_session'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-screenshot-1.0.13/lib/capybara-screenshot/rspec.rb:54:in `after_failed_example'
          # /Users/lukegrecki/.rvm/gems/ruby-2.3.1@backoffice/gems/capybara-screenshot-1.0.13/lib/capybara-screenshot/rspec.rb:84:in `block (2 levels) in <top (required)>'
          # ./spec/ui_spec_helper.rb:53:in `block (2 levels) in <top (required)>'
          # ------------------
          # --- Caused by: ---
          # Errno::ECONNRESET:
          #   Connection reset by peer
          #   <internal:prelude>:76:in `__read_nonblock'

To give a little more context I'm stubbing about 8 requests total and these may be coming in rather fast. The first set of 4 requests are options requests, and the second set of 4 requests have the same urls as the first but are get requests asking for data.

I know puffing-billy doesn't parallelize the processing of mock requests. Could too many ajax requests coming into capybara-webkit + puffing-billy cause a crash? Any ideas how to work around this?

@lukegrecki
Copy link
Author

This turned out to be an issue locally for me (still unsolved) but it passes locally consistently for someone else on the team.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants