How to use multiple storage states in different devices (browsers)

54 views Asked by At

So I have spent my day banging my head against a wall trying to figure this out. What I have is a set of tests, a subset of which have to be run in 2 browsers, but the rest only need to be run in one(chromium).

I've got them defined in playwright.config.ts this way:

 projects: [

{
  name: 'setup',
  testDir: './',
  testMatch: /.*\.setup\.js/
},

{
  name: 'Desktop Chrome',
  use: {
    browserName: 'chromium',
    storageState: '.auth/specialuser1.json'
  },
  dependencies: ['setup']
},

{
  name: 'Desktop Firefox',
  use: {
    browserName: 'firefox',
    storageState: '.auth/specialuser2.json'
  },
  dependencies: ['setup']
},

The problem I have is that while this works just fine for the subset of tests, when I need to run the rest of the tests in chromium, I can't use that storagestate 'specialuser1.json'. I need to do a normal login process using other sets of credentials in the beforeAll for those tests.

How can I define/configure this so that it ONLY uses the storage state if I'm running the special subset of tests?

Note that I've already went down the path of creating a duplicate of the Desktop Chrome section, like so:

    {
  name: 'Special Chrome',
  testDir: '/specialtests'
  use: {
    browserName: 'chromium',
    storageState: '.auth/contractsuser1.json'
  },
  dependencies: ['setup']
},

And adding a corresponding line in the 'Desktop Chrome' section to ignore the special tests and removing the storage state line:

   {
  name: 'Special Chrome',
  testIgnore: '/specialtests'
  use: {
    browserName: 'chromium',
  },
  dependencies: ['setup']
},

But when I kick off the job to run the special tests, because of that ignore line, it tells me there are no tests found.

Dan

0

There are 0 answers