'How to run multiple tests under same fixture with same browser session

I am trying to test multiple features in one test.js file with each feature implemented as a test. All these tests can be run only after login to the portal. Testcafe closes the browser after the first test which fails the subsequent tests. I used Role and .beforeEach so that the tests can log in to the portal and proceed as usual but is there any easy way to just continue all the tests in the same browser session without really closing them after each test?

I used Role feature and .beforeEach which looks like a workaround to me. Is there any other way to run all tests one after another without really closing the browser session. This will save us the login operation and the instability that might cause for each test.

import { Selector , ClientFunction, Role } from 'testcafe';
import loginpage from '../../features/blah/login/page-model'
const appPortalUser2 = Role('https://test.com', async t => {
    await loginpage.signInToPortal()
    await loginpage.login('test-userm', 'Password123')
}, { preserveUrl: true });

fixture `portal - settings`
    .page `https://test.com/apps`
    .beforeEach (async  t => {
        await t`enter code here`
        .useRole(appPortalUser2)
});

test('settings', async t => {
    //test1
    await loginpage.foo1()
});

test('backup', async t => {
    //test2
    await loginpage.foo2()
});

Actual behavior: after test1 browser exits and login page appears which fails test2 without using .beforeEach.

Expected: browser session should continue for test2 after test1 without .beforeEach. Provide such an option where tests can continue without creating new browser sessions each time.



Solution 1:[1]

At the moment, there is no such option in the public API.

The idea is that one test should not affect another test in any way. If all tests had run in one browser session, every test would have influenced all preceding tests as it could have had a page with an invalid state.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alexey Lindberg