【问题标题】:How to avoid writing browser cookies when running testcafe tests?运行 testcafe 测试时如何避免写入浏览器 cookie?
【发布时间】:2019-04-18 18:40:39
【问题描述】:

我正在为一个网站运行 testcafe 测试。我想避免在运行我的 testcafe 测试时编写任何浏览器 cookie。我的网站会写入 cookie,但在运行测试时我想避免这种情况。有什么办法可以在 testcafe 中实现这一点?

【问题讨论】:

    标签: cookies automated-tests e2e-testing web-testing testcafe


    【解决方案1】:

    要在 Google Chrome 浏览器中禁用 cookie,请按以下步骤操作:

    • 在 Google Chrome 配置文件中找到“首选项”文件,并将 2 指定为 profile.default_content_settings.cookies 键值。
    • 在浏览器别名后指定 :userProfile 标志。
    testcafe 'chrome:userProfile' /tests
    

    【讨论】:

      【解决方案2】:

      如果您希望在测试开始时不使用 cookie,请注意 TestCafe 在每次测试开始之前会自动清除 cookie。

      如果您想在测试场景的某个时刻清除 cookie,例如,如果您想以不同的用户身份进行身份验证,您可以使用 Role

      如果您的场景更复杂,请查看 RequestMockRequestHook - 它们允许您在测试会话期间控制所有请求和响应的任何方面。

      【讨论】:

      • 我想在启动 testcafe 时阻止 chrome 中的 cookie。 Chrome 有一个设置来阻止 cookie 写入。有没有办法用这个浏览器设置启动 testcafe。
      猜你喜欢
      • 2019-08-25
      • 2019-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-10
      • 2020-06-03
      • 1970-01-01
      相关资源
      最近更新 更多