TypeError: arguments[0] is null
mockdeep opened this issue · comments
Meta
Capybara Version:
3.39.2
Driver Information (and browser if relevant):
Ruby 3.2.2, Selenium Webdriver 4.16.0, Firefox 121.0
Expected Behavior
Consistently passing tests.
Actual Behavior
I've got a matcher using Capybara that fails fairly frequently when negated. it fails with the error:
Selenium::WebDriver::Error::JavascriptError:
TypeError: arguments[0] is null
I've caught the error in my tests and put in a binding when it happens, but there is no error in the browser console.
Steps to reproduce
It's not a consistent repro. I see it every 5th or 6th test that uses the matcher. The error only happens in the negated does_not_match?
method. TAGS_SELECTOR
is '.tag-buttons a.button'
, but I've also tried it with '.tag-buttons > div > a.button'
and the error still happens. Here is the matcher:
module Questlog
module Matchers
class HaveTag
attr_accessor :expected, :actual
def initialize(expected)
self.expected = expected
end
def matches?(actual)
self.actual = actual
actual.has_selector?(TAGS_SELECTOR, text: expected)
end
def does_not_match?(actual)
actual.has_no_selector?(TAGS_SELECTOR, text: expected)
end
def failure_message
if actual.has_selector?(TAGS_SELECTOR)
found_tags = actual.all(TAGS_SELECTOR).map(&:text)
%(expected to find tag "#{expected}", but found #{found_tags})
else
%(expected to find tag "#{expected}", but no tags found)
end
end
def failure_message_when_negated
%(expected not to find tag "#{expected}", but it is present)
end
end
end
end
Something else of note is that I have a similar matcher that I have not seen this error from. It's basically the same, only that the selector is '.task-input:not(#new-title)'
. One other thing of note is that the tags section is rendered in React, so it may not immediately be in the page, or may be popping into the page.
Relevant log output
Selenium::WebDriver::Error::JavascriptError:
TypeError: arguments[0] is null
# @http://127.0.0.1:8081/:3:1
# @http://127.0.0.1:8081/:7:8
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/response.rb:55:in `assert_ok'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/response.rb:34:in `initialize'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/common.rb:83:in `new'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/common.rb:83:in `create_response'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/default.rb:103:in `request'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/http/common.rb:59:in `call'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/bridge.rb:601:in `execute'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/remote/bridge.rb:331:in `execute_script'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/selenium-webdriver-4.16.0/lib/selenium/webdriver/common/driver.rb:225:in `execute_script'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/selenium/driver.rb:137:in `execute_script'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/selenium/extensions/find.rb:31:in `gather_hints'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/selenium/extensions/find.rb:22:in `find_by'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/selenium/extensions/find.rb:11:in `find_css'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/base.rb:110:in `find_css'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/queries/selector_query.rb:253:in `find_nodes_by_selector_format'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/queries/selector_query.rb:166:in `block in resolve_for'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/base.rb:77:in `synchronize'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/queries/selector_query.rb:165:in `resolve_for'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/matchers.rb:844:in `block in _verify_selector_result'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/base.rb:84:in `synchronize'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/matchers.rb:843:in `_verify_selector_result'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/matchers.rb:234:in `assert_no_selector'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/matchers.rb:51:in `block in has_no_selector?'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/matchers.rb:877:in `make_predicate'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/node/matchers.rb:51:in `has_no_selector?'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/session.rb:773:in `has_no_selector?'
# ./spec/support/matchers/have_tag.rb:19:in `does_not_match?'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/capybara-3.39.2/lib/capybara/rspec/matchers/base.rb:92:in `matches?'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:51:in `block in handle_matcher'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:27:in `with_matcher'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/handler.rb:48:in `handle_matcher'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/expectation_target.rb:65:in `to'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-expectations-3.12.3/lib/rspec/expectations/expectation_target.rb:101:in `to'
# ./spec/features/tag_counters_spec.rb:51:in `block (2 levels) in <main>'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:263:in `instance_exec'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:263:in `block in run'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:511:in `block in with_around_and_singleton_context_hooks'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:468:in `block in with_around_example_hooks'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:486:in `block in run'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:626:in `block in run_around_example_hooks_for'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:352:in `call'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-rails-6.1.0/lib/rspec/rails/adapters.rb:75:in `block (2 levels) in <module:MinitestLifecycleAdapter>'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:457:in `instance_exec'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:457:in `instance_exec'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:390:in `execute_with'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:628:in `block (2 levels) in run_around_example_hooks_for'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:352:in `call'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:629:in `run_around_example_hooks_for'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/hooks.rb:486:in `run'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:468:in `with_around_example_hooks'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:511:in `with_around_and_singleton_context_hooks'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example.rb:259:in `run'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:646:in `block in run_examples'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:642:in `map'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:642:in `run_examples'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/example_group.rb:607:in `run'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:121:in `block (3 levels) in run_specs'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:121:in `map'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:121:in `block (2 levels) in run_specs'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/configuration.rb:2070:in `with_suite_hooks'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:116:in `block in run_specs'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/reporter.rb:74:in `report'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:115:in `run_specs'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:89:in `run'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:71:in `run'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/lib/rspec/core/runner.rb:45:in `invoke'
# /home/fletch/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/rspec-core-3.12.2/exe/rspec:4:in `<top (required)>'
# /home/fletch/.asdf/installs/ruby/3.2.2/bin/rspec:25:in `load'
# /home/fletch/.asdf/installs/ruby/3.2.2/bin/rspec:25:in `<main>'
# /home/fletch/.asdf/installs/ruby/3.2.2/bin/ruby_executable_hooks:22:in `eval'
# /home/fletch/.asdf/installs/ruby/3.2.2/bin/ruby_executable_hooks:22:in `<main>'
Try setting ENV['DISABLE_CAPYBARA_SELENIUM_OPTIMIZATIONS'] = true and see if the error goes away
problem is from the information provided it's not possible to tell whether elements is nil or a member of elements of is somehow nil
I'll give that a try. Not sure if it helps, but here is the repo, and here is a failing build.
should be suppressed in the master branch, potentially not the best solution from a performance perspective but should mask it without being able to tell the root cause