Is it possible to preserve login state during development in playwright ui mode?

358 views Asked by At

I configured my project as described here: https://playwright.dev/docs/auth, to store state after login, and it works fine in subsequent tests. My question is whether it's possible to maintain state during the development cycle. I would like to open the Playwright UI, perform the login steps once, and then work on my spec file without the need to log in every time I rerun a single test.

My current simplified setup below:

// auth.setup.ts
import {test as setup, expect } from '@playwright/test';

const sessionFile = 'playwright/.auth/session.json';

setup('login', async ({ page }) => {
    await page.goto('/');
    // some login steps here...

    await page.context().storageState({ path: sessionFile });
});
//playwright.config.ts
...
  projects: [
    {
      name: 'setup',
      testMatch: /.*\.setup\.ts/
    },
    {
      name: 'chromium',
      use: { ...devices['Desktop Chrome'] },
      dependencies: ['setup'],
    },
  ]
...
// my.spec.ts
import { test, expect } from '@playwright/test';

test.use({ storageState: 'playwright/.auth/session.json' });

test('should pass', async ({ page }) => {
  await page.goto('/some/page');
  ...
});
1

There are 1 answers

0
slayerette On

Once you've run your setup once locally, then your files will be created with the saved login state(s). You can then untick your setup project at the top-left of the Playwright UI, which will stop the setup from running again.

Select the projects that you want to be able to run.