localStorage.clear() error when Capybara test fails before visiting page
If an error happens in a capybara test before selenium has "visited" a page, it will fail as it attempts to clean up localStorage
.
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)>'
This can make it confusing at first glance when looking for the actual spec failure because it can appear to have something to do with Selenium::WebDriver when in fact that secondary failure is just a side effect of the first.
I propose we conditionally run the localStorage.clear()
command only when Capybara is on a non-blank page so that these errors no longer appear.
Edited by Mike Greiling