3

I have a test suite(fixture) with multiple functional tests for test cafe. They look something like this:

fixture('Test suite')
  .page(login_url)
  .beforeEach(async (t) => {
    await t.maximizeWindow()
    await page.signIn('username', 'pass');
  });

test('Test case 1', async (t) => {
  await t.expect(page.title.textContent).eql('My Page');}
test('Test case 2', async (t) => {
  await do some other stuff}

This obviously wastes a lot of time before each test because we need to log in each time. How do I log in once, set that page as an entry point, and start each test from that page?

  • 1
    Just a comment to illustrate where the problems is. Firstly, fixture hooks do not have access to the tested page. This could be dealt with using a variable and condition to execute some code in beforeEach hook only once. But the real problem is that TestCafe deletes everything (cache, cookies etc.) before each test as mentioned [here](https://testcafe-discuss.devexpress.com/t/how-do-you-delete-all-the-cookies-for-the-current-session-in-testcafe/1000). Therefore logging only once is a real trouble in TestCafe. I deleted my answer, because it suggested a workaround only for the first problem. – pavelsaman Dec 24 '20 at 16:13

1 Answers1

3

You can use the TestCafe Roles mechanism to log in only once. All further tests will not require additional authentication. Take a look at the following article for details: https://devexpress.github.io/testcafe/documentation/guides/advanced-guides/authentication.html#user-roles

Alex Kamaev
  • 6,198
  • 1
  • 14
  • 29