TestCafe - The browser always starts in clean slate between the tests. How to override this so that browser remembers cache, user settings and storage

醉酒当歌 提交于 2019-12-10 21:44:22

问题


The browser between the Tests is always open in a clean slate. The Login is remembered in my application as Authentication persists but as the browser is opened in clean slate always, I have to perform Login in Before hook of all Fixtures. Is there some way I can open browser so that user settings, cache, local and session storage are remembered?


回答1:


TestCafe doesn't offer a way to store the page state between tests and encourages writing independent tests. However, Roles API may meet some of your needs (refer to this comment for more details).




回答2:


This is how I resolved using Role API.

Login.js page object file

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);
});

Then I called this const Login in my fixture file as shown below : fixture.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');
});


来源:https://stackoverflow.com/questions/56975267/testcafe-the-browser-always-starts-in-clean-slate-between-the-tests-how-to-ov

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!