Closed bondar-artem closed 10 months ago
Works fine for me. Note that you are using fs.writeFileSync
with relative path (resolved relative to CWD), so your tests aren't working in the general case. You should always path.resolve(__dirname, '../auth/user.json')
or require.resolve('../auth/user.json')
to get consistent path that does not depend on the folder you run your tests from.
@pavelfeldman I don't think that fs.writeFileSync
it's the case.
You can remove the auth.setup.ts from the project altogether, only leaving the user.json file with a valid token. Then read this file in playwright.config.ts. Like this:
export default defineConfig({
testDir: './tests',
reporter: 'html',
use: {
trace: 'on-first-retry',
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'], storageState: '.auth/user.json' }
}
]
});
And it's reproducible on my end. With Playwright 1.39 - the storage state is not set
With Playwright 1.38 and earlier versions - it is working fine.
@bondar-artem I can reproduce the issue. Your site behaves differently between Chrome 117.0.5938.62 that comes with Playwright 1.38.1 and Chrome 119.0.6045.9 that comes with Playwright 1.39.0. Setting localStorage.jwtToken
results in a 401 request in the newer Chrome.
I'd say Playwright has found a bug on your site that breaks with the browser update. Sounds like a success story 🎉 Happy testing!
I'd say Playwright has found a bug on your site that breaks with the browser update. Sounds like a success story 🎉 Happy testing!
@dgozman Could you please let me know how did you get 401? I have just updated my Chrome to 119.0.6045.9, then manually navigated to the application, clicked Sign In, entered my username and password, and was successfully authorized.
@bondar-artem I evaluated localStorage.jwtToken = "...."
in DevTools Console with the value from user.json
and reloaded the page.
@dgozman I tried it, worked for me just fine in Chrome 119. No errors. Probably you have 401 because you took the expired token from the repo. Generate a new token with username and password.
Local storage:
But if you do the same in the Playwright, you will see that Local storage in the browser remains empty after the execution
@bondar-artem I just tried the following in Chrome 120.0.6099.5
localStorage.jwtToken
is therelocalStorage.jwtToken
is now empty, cleaned up by the siteI'd say Playwright works the same way as I did manually.
@dgozman Thank you! You are right, the issue is identified on my side
System info
Source code
Link to the GitHub repository with the repro
https://github.com/bondar-artem/playwright-bug
Steps
Expected
when application opens, user should be already looged in
Actual
user is not logged in
When downgrade to Playwright 1.38, the test works as expected and user session is authorized when application opens