Skip to content

Resolve "localStorage.clear() error when Capybara test fails before visiting page"

This change prevents localStorage.clear() from running when no page has been visited in a Capybara test. This will prevent confusion when unrelated test failures occur before visiting pages in our feature tests.


I've run this patch against EE which is currently failing with one of these errors:

Before:

https://gitlab.com/gitlab-org/gitlab-ee/-/jobs/54119553

Failures:

  1) Subgroup Issuables shows the full subgroup title when issues index page is empty
     Got 0 failures and 2 other errors:

     1.1) Failure/Error: let!(:group)    { create(:group, name: 'group') }

          ActiveRecord::RecordInvalid:
            Validation failed: Path has already been taken
          # ./spec/features/projects/sub_group_issuables_spec.rb:4:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:196:in `block (2 levels) in <top (required)>'

     1.2) Failure/Error: execute_script("localStorage.clear();")

          Selenium::WebDriver::Error::NoScriptResultError:
            <unknown>: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.
              (Session info: headless chrome=63.0.3239.108)
              (Driver info: chromedriver=2.33.506092 (733a02544d189eeb751fe0d7ddca79a0ee28cce4),platform=Linux 4.13.5-coreos-r2 x86_64)
          # ./spec/support/capybara.rb:82:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:196:in `block (2 levels) in <top (required)>'

After:

https://gitlab.com/gitlab-org/gitlab-ee/-/jobs/54126736

  1) Subgroup Issuables shows the full subgroup title when issues index page is empty
     Failure/Error: let!(:group)    { create(:group, name: 'group') }

     ActiveRecord::RecordInvalid:
       Validation failed: Path has already been taken
     # ./spec/features/projects/sub_group_issuables_spec.rb:4:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:196:in `block (2 levels) in <top (required)>'

Closes #43570 (closed) Related to: gitlab-org/gitlab-ce#40677

Edited by Mike Greiling

Merge request reports