question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Update storageState to refresh token

See original GitHub issue

I’m using Keycloak with a 30min refresh token. My test suite is longer than that and promptly at 30min it fails. I’m following the multiple sign-in roles pattern to generate two json files in my global-setup. Once I discovered the issue I assumed I needed to simply refresh my json files. So I created a method to do that in my utilities:

async saveStorageState(file = 'storageState.json') {
  await this.page.context().storageState({ path: file })
}

I called it in several of my test cases but my tests still fail at exactly 30min. Am I updating the storageState.json correct? Can this be updated outside of the global-setup?

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
jmthomascommented, Aug 21, 2022

I was unable to get the storageState thing to work so I switched to fixtures and came up with the following:

import { test as base } from '@playwright/test'
// Extend the page fixture to goto the OpenC3 tool and wait for potential
// redirect to authentication login
export const test = base.extend({
  toolPath: '/tools/cmdtlmserver',
  page: async ({ baseURL, toolPath, page }, use) => {
    page['utils'] = new Utilities(page)
    await page.goto(`${baseURL}${toolPath}`, {
      waitUntil: 'networkidle',
    })
    // Check to see if we redirect to authenticate
    if (page.url().includes('/auth/')) {
      await page.locator('input[name="username"]').fill('operator')
      await page.locator('input[name="password"]').fill('operator')
      await Promise.all([
        page.waitForNavigation(),
        page.locator('input:has-text("Sign In")').click(),
      ])
      await page.context().storageState({ path: 'storageState.json' })
    }
    await use(page)
  },
})
export { expect } from '@playwright/test'
0reactions
jmthomascommented, Aug 19, 2022

@aslushnikov Does playwright cache or otherwise use the same storageState file given in the global-setup or does it re-read it each time it creates a new browser context?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I update my access token with a refresh token in msal?
MSAL takes care of refresh token for you. What you should do is always ask a token from MSAL before using one. If...
Read more >
How to Handle Authentication in E2E Testing with Playwright
Let's start with the requirements first and answer the question, ... For instance, in our case, the access token was valid for a...
Read more >
Understanding Refresh Tokens - Auth0
Learn about refresh tokens and the role they serve in the authorization ... To solve this problem, OAuth 2.0 introduced an artifact called...
Read more >
Authentication | Playwright - CukeTest
Web apps use cookie-based or token-based authentication, where authenticated state is stored as cookies or in local storage. Playwright provides browserContext.
Read more >
Update token lifetime - Microsoft Q&A
I have a SPA application, which authenticates the login with the azure ad, i get access token that expires in 60 minutes... How...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found