问题
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