Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `+' for nil:NilClass #2120

Closed
boris-petrov opened this issue Oct 29, 2018 · 9 comments
Closed

undefined method `+' for nil:NilClass #2120

boris-petrov opened this issue Oct 29, 2018 · 9 comments

Comments

@boris-petrov
Copy link

Capybara 3.10.0, Selenium 3.14.1 used via JRuby.

     NoMethodError:
       undefined method `+' for nil:NilClass
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/selenium/node.rb:184:in `path'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/node/element.rb:442:in `inspect'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/queries/selector_query.rb:52:in `description'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/queries/selector_query.rb:57:in `applied_description'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/queries/selector_query.rb:115:in `failure_message'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/result.rb:105:in `failure_message'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/node/matchers.rb:104:in `block in assert_selector'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/node/matchers.rb:740:in `block in _verify_selector_result'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/node/base.rb:82:in `synchronize'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/node/matchers.rb:739:in `_verify_selector_result'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/node/matchers.rb:102:in `assert_selector'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/rspec/matchers.rb:67:in `element_matches?'
     # ./features/build/tmp/jrubyExec/gems/capybara-3.10.0/lib/capybara/rspec/matchers.rb:51:in `matches?'
     ...

This is very sporadic in our test suite and I'm not sure what's causing it but in any case Capybara should give an error message and not blow up with a NoMethodError. Please tell me how I can help more.

@twalpole
Copy link
Member

What type of element is the scoping element you are searching within ?

@boris-petrov
Copy link
Author

This is the code that causes this exception:

dropdown = find('.navbar a', text: 'Some text').find(:xpath, './following-sibling::*[1]', visible: :all)
expect(dropdown).to have_css('a', visible: :all, exact_text: name)

The second line is followed by the stacktrace that I pasted earlier.

@twalpole
Copy link
Member

twalpole commented Oct 29, 2018

The following-sibling is creating an issue when trying to generate the path of the scoping element (because it is outside its “parent” sub tree) if no matching ‘a’ element is found. I’ll try and have a fix out later today (California time)

@twalpole
Copy link
Member

twalpole commented Oct 29, 2018

@boris-petrov In the meantime you should be able to workaround the issue by combining the two finds so there is no scoping happening with something like

dropdown = find(:xpath, XPath.css('.nabvar a')[XPath.contains('Some text')].following_sibling[1], visible: :all)

@twalpole
Copy link
Member

twalpole commented Oct 29, 2018

Hmmm -- this might not actually have anything to do with the sibling portion of it -- is it possible the dropdown element is going away while have_css is running? and is this all running inside a within block by any chance?

@twalpole
Copy link
Member

I have not been able to reproduce this - but have put in a fix at the current point of failure - Please try branch issue_2120 and see if that fixes things for you.

@boris-petrov
Copy link
Author

boris-petrov commented Oct 30, 2018

Thanks for the support! This code is not run in a within block, however it is possible that the dropdown is rerendered, yes. Which means that it disappears and is redrawn. We expect that in this case Capybara would just retry the have_css check. Is that wrong as an assumption? We use a single-page-application framework (Ember.js) which redraws stuff all the time and such race-conditions are ubiquitous.

P.S. I'll try your fix. But, as I said, it is sporadic so we'll see how long it takes. :)

@twalpole
Copy link
Member

@boris-petrov Yes it should retry (if the undefined method error hadn't raised), I was just trying to narrow down how the error came about so I could generate a test case for it.

@twalpole
Copy link
Member

twalpole commented Oct 30, 2018

I've merged this in to master branch now -- I'm going to close this issue, we can reopen if the problem shows up again.

@lock lock bot locked and limited conversation to collaborators Aug 16, 2019
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