Posted over 2 years ago. Visible to the public. Repeats.

Cucumber: Clear localStorage after each scenario

Capybara clears cookies before each scenario, but not other client-side data stores. If your app is using localStorage or sessionStorage, contents will bleed into the next scenario.

Use this hook to remove all site data after each scenario:

Copy
After do if Capybara.current_driver == :selenium && !Capybara.current_url.starts_with?('data:') page.execute_script <<-JAVASCRIPT localStorage.clear(); sessionStorage.clear(); JAVASCRIPT end end

Once an application no longer requires constant development, it needs periodic maintenance for stable and secure operation. makandra offers monthly maintenance contracts that let you focus on your business while we make sure the lights stay on.

Owner of this card:

Avatar
Henning Koch
Last edit:
over 2 years ago
by Arne Hartherz
Keywords:
site, data
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more