【问题标题】:TestCafe - The browser always starts in clean slate between the tests. How to override this so that browser remembers cache, user settings and storageTestCafe - 浏览器在测试之间总是从头开始。如何覆盖它以便浏览器记住缓存、用户设置和存储
【发布时间】:2019-11-20 08:24:30
【问题描述】:

测试之间的浏览器始终以全新状态打开。登录在我的应用程序中被记住,因为身份验证仍然存在,但由于浏览器总是以干净的状态打开,我必须在所有夹具的钩子之前执行登录。 有什么方法可以打开浏览器,以便记住用户设置、缓存、本地和会话存储?

【问题讨论】:

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


    【解决方案1】:

    TestCafe 不提供在测试之间存储页面状态的方法,并鼓励编写独立的测试。但是,Roles API 可能会满足您的一些需求(请参阅this 评论了解更多详情)。

    【讨论】:

      【解决方案2】:

      这就是我使用 Role API 解决的方法。

      Login.js 页面对象文件

      const loginBtn = Selector('[type="submit"]');
      const password = Selector('input[placeholder="Password"]');
      const userName = Selector('input[placeholder="Email"]');
      export const login = Role(`http://example.com/login`, async t => {
        await t
          .typeText(userName, `abc`)
          .typeText(password, `password`)
          .click(loginBtn);
      });
      

      然后我在我的夹具文件中调用了这个 const Login,如下所示: 夹具.js

      import { login } from '../page-objects/login';
      fixture('Example Fixture').beforeEach(async t => {
        await t.useRole(login).navigateTo('url of the page that you want to open');
      });
      

      【讨论】:

        猜你喜欢
        • 2021-08-02
        • 2011-08-22
        • 2020-06-03
        • 2012-07-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多