kolodny / safetest

MIT License
1.38k stars 34 forks source link

how to set localStorage for every test ? #35

Closed alexis-dorosz closed 5 months ago

alexis-dorosz commented 5 months ago

hey there ! been struggling with setting localStorage keys for a very basic authentification before every test I am not too familiar with playwright and i've been trying to add a a playwright.config.ts with the "use.storageState" pointing at a json with the following shape with no success

{
    "cookies": [],
    "origins": [
      {
        "origin": "localhost",
        "localStorage": [
          {
            "name": "auth_token",
            "value": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9"
          }
        ]
      }
    ]
  }

I'v seen your doc recommands cookies, how would you approach localStorage available for every test with safeTest ?

thank you very much

TomaszG-OpenX commented 2 months ago

@alexis-dorosz, do you have any ideas on how to do it? I know that you can do it during render:

  const { page } = await render(<Component />,
      {
        storageState: './.auth/storageState.json',
      }
  )

but how to do it globally?