I am running tests using Rspec, Capybara, Cucumber, and Selenium webdriver
. For my app, if a user is a first time visitor to the site, a pop-up appears after 10 seconds, asking the user to signup for a newsletter. Whether the user signs up or not, a value gets saved to the browsers local storage
, specifying that the user has viewed the pop-up (I do this so it doesn't popup every visit).
For some of my tests the popup gets in the way since it loads for every new scenario. What I want to do is before a scenario is run, to save a value to local storage before running the test, this way the popup doesn't appear. So far I have a before hook that specifies which scenarios should not have the popup:
Before('@no-newsletter') do
page.execute_script "window.localStorage.setItem('subscribed','viewed');"
end
However, when I run this I get the following error:
SecurityError: The operation is insecure. (Selenium::WebDriver::Error::JavascriptError)
I can't figure out how to correct this issue and save a value to local storage. Any ideas?