thoughtbot / capybara-webkit

A Capybara driver for headless WebKit to test JavaScript web apps
https://thoughtbot.com/open-source
MIT License
1.97k stars 428 forks source link

Intermittent issue with log out #997

Closed gardha closed 6 years ago

gardha commented 7 years ago

Hello,

I have the following setup (latest versions for all): capybara (2.13.0) capybara-webkit (1.14.0) database_cleaner (1.5.3) Qt 5.5 MacOS Sierra

I am intermittently getting the following errors when attempting to log out my application

     Failure/Error: Unable to find matching line from backtrace
     NoMethodError:
       undefined method `click' for nil:NilClass
     # ./spec/support/feature_helpers.rb:19:in `log_out'
     # ./spec/support/feature_class_helpers.rb:37:in `block in with_login_user'
     # ./spec/spec_helper.rb:75:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:68:in `times'
     # ./spec/spec_helper.rb:68:in `block (2 levels) in <top (required)>'
     # /Users/gardha/.rvm/gems/ruby-2.3.0/gems/rspec-retry-0.3.0/lib/rspec/retry.rb:36:in `block (3 levels) in apply'
     # /Users/gardha/.rvm/gems/ruby-2.3.0/gems/rspec-retry-0.3.0/lib/rspec/retry.rb:27:in `times'
     # /Users/gardha/.rvm/gems/ruby-2.3.0/gems/rspec-retry-0.3.0/lib/rspec/retry.rb:27:in `block (2 levels) in apply'

The page seems to have no content save_and_open_page output

<!DOCTYPE html><html><head>
  <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
    <title>        My Title
</title>
  <meta name="description" content="abc">
  <meta name="robots" content="noindex">
  <link rel="stylesheet" media="all" href="/assets/application.css" data-turbolinks-track="true">
  <script src="/assets/application.js" data-turbolinks-track="true"></script></head></html>

Thanks, any help would be appreciated!

twalpole commented 7 years ago

If the page has no content then there is nothing to click on, and I guess you're using first rather than find to locate the item you want to click on, which disables Capybaras waiting behaviors. Show the code for your test.

gardha commented 7 years ago

Your right, I am using first as opposed to find. I have now changed the code to use find to make the test more stable. What I don't understand is why the page would load without the content intermittently. Could it be related to #724

    def log_out
      begin
      visit '/'
      find('.dropdown-toggle').click
      click_link 'Logout'
      expect(page).to have_content 'You have been successfully logged out.'
      rescue
        puts 'Intermittent issue logging out.'
      end
    end
twalpole commented 7 years ago

Sure it could be, or it could be throttling you have set up in your app, or it could be something else entirely. Try the fix mentioned at the end of #724 and see if it fixes it for you. Your test.log should also show whether your app was responding with a 304 message which would imply it is issue #724

twalpole commented 6 years ago

Closing due to lack of response