Cucumber:使用Poltergeist(PhantomJS)禁用或删除本地存储

Cucumber:使用Poltergeist(PhantomJS)禁用或删除本地存储,cucumber,capybara,phantomjs,poltergeist,Cucumber,Capybara,Phantomjs,Poltergeist,正在尝试为Cucumber测试禁用或删除本地存储 我尝试了以下方法: page.driver.execute_script("localStorage.clear()") 但是我收到以下错误 One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false

正在尝试为Cucumber测试禁用或删除本地存储

我尝试了以下方法:

page.driver.execute_script("localStorage.clear()")
但是我收到以下错误

 One or more errors were raised in the Javascript code on the page. If you don't care about these errors, you can ignore them by setting js_errors: false in your Poltergeist configuration (see documentation for details).

  SECURITY_ERR: DOM Exception 18: An attempt was made to break through the security policy of the user agent.
  at phantomjs://webpage.evaluate():1
  at phantomjs://webpage.evaluate():1
  at phantomjs://webpage.evaluate():1
  at phantomjs://webpage.evaluate():1 (Capybara::Poltergeist::JavascriptError)
我所做的是:

  visit '<the_url_needed>'
  page.execute_script('if (localStorage && localStorage.clear) localStorage.clear()')
访问“
page.execute_脚本('if(localStorage&&localStorage.clear)localStorage.clear()

希望有帮助

我也犯了同样的错误。问题是,我试图在不首先访问页面的情况下执行脚本。这会抛出上面Justin解释的错误:

shared_context'@用户已登录'do
在做之前
#访问“/”
凭据=@user.create\u new\u auth\u令牌
令牌=凭证['access-token']
page.execute_脚本“localStorage.setItem('token','#{token}')”
结束
结束
这项工作:

shared_context'@用户已登录'do
在做之前
访问“/”
凭据=@user.create\u new\u auth\u令牌
令牌=凭证['access-token']
page.execute_脚本“localStorage.setItem('token','#{token}')”
结束
结束

以下是Justin打开的水豚网络工具包票证供参考: