Playwright doesn't store complete local storage

36 Views Asked by At

`Hi, I'm trying to skip login steps in my test using Playwright Local Storage, but from some reason file that is create contains only few information which I cannot use in order to skip login. Do you maybe know what is the issue here?

This the code I use

test('Positive Login', async ({page}) => {
    const authFile = 'e2e/.auth/userAuth.json'
    
    await loginPage.loginToApp(login_email, login_password);
    await loginPage.clickLoginButton();
    await page.context().storageState({ path: authFile });
  })

But userAuth.json file have only those info

  "cookies": [],
  "origins": [
    {
      "origin": "https://staging.uxtest.oculid.com",
      "localStorage": [
        {
          "name": "userpilotSettings",
          "value": "{\"endpoint\":\"wss://analytex-eu.userpilot.io/v0/events/websocket\",\"date\":1710280985903}"
        },
        {
          "name": "userpilotSDK",
          "value": "{}"
        }
      ]
    }
  ]
}

I don't know why stores only this, but not all necessary informations

1

There are 1 best solutions below

0
togi On

You have to pass "page" as an argument to loginPage.loginToApp and loginPage.clickLoginButton. if you don't, state of page will not change. That's why userAuth.json file have only origin info.

Example:

test('Positive Login', async ({page}) => {
    const authFile = 'e2e/.auth/userAuth.json'
    
    await loginPage.loginToApp(page, login_email, login_password);
    await loginPage.clickLoginButton(page);
    await page.context().storageState({ path: authFile });
  })