Posted about 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

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Avatar
Henning Koch
Last edit:
about 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