Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 778
Jn Neer Avatar asked Mar 03 '23 17:03

Jn Neer


2 Answers

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).

like image 104
Arseniy Rubtsov Avatar answered Mar 06 '23 13:03

Arseniy Rubtsov


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');
});
like image 23
Jn Neer Avatar answered Mar 06 '23 14:03

Jn Neer