Closed gauravgandhi1315 closed 1 year ago
Is anything wrong I am doing in this case? Can someone please help?
Two moment are possible: 1) Just simple mistake, try to name your path in global setup as "storageState.json" instead of storageState and also check that location of saved file and file in config are the same
2) Authorisation in your app can work not rellaing on cookies
@v-romant Its still not working as per your suggestion
@gauravgandhi1315 can you log storage state content to console in global setup and in the test and check if it contains same data?
in global setup:
await page.context().storageState({ path: storageState });
console.log(await page.context().storageState());
await browser.close();
in the test:
console.log(await page.context().storageState());
await page.goto("URL");
await verifyActions.verifyElementEnabled('#page-header');
@yury-s I just checked and it does contain the same data
I am not sure what this array is origins: [ { origin: 'URL', localStorage: [Array] } ]
If the content is the same it means that the state in the global setup is successfully picked up in the tests. In that case it's likely case 2 that @v-romant mentioned above and your app relies on something else besides cookies for authentication. Note that Playwright persists only cookies and localStorage state into storageState file.
It might be that the app stores some parts of the authenticated state in session storage, in that case you may do what is described in this doc. I'd recommend you consult with the app developers to learn what else besides cookies and local storage is necessary to persist the authentication state of the app between browser runs.
We need more information to act on this report. As long as we can't repro it, it is unlikely with can make progress with it. Allow me to close it, but please file a new one and link to this issue when you get back to it!
@gauravgandhi1315 I am more than sure that the problem is that your site doesn't allow you to authorize using cookies. (For example, Spotify will not allow you to enter in this way). Global storageState works fine.
Having the same issue as yours. While debugging, I found an interesting thing that looks like a bug with a "storageState" fixture.
When my config looks like this, and I have a dependent "setup" project step everything works:
projects: [ {name: 'setup', testMatch: 'auth.setup.ts' }, { name: 'chromium', use: { ...devices['Desktop Chrome'], storageState: '.auth/user.json' }, dependencies: ['setup'] } ]
But it I remove "dependencies" section, which triggers 'auth.setup.ts'. It does not work! But it should, because "user.json" file is still valid and has a valid token needed for authorization of the browser.
storageState fixture for some reason not set the authorization based on the file content, despite file is 100% valid
This application has only token-based authorization without cookies at all.
Having the same issue as yours. While debugging, I found an interesting thing that looks like a bug with a "storageState" fixture.
When my config looks like this, and I have a dependent "setup" project step everything works:
projects: [ {name: 'setup', testMatch: 'auth.setup.ts' }, { name: 'chromium', use: { ...devices['Desktop Chrome'], storageState: '.auth/user.json' }, dependencies: ['setup'] } ]
But it I remove "dependencies" section, which triggers 'auth.setup.ts'. It does not work! But it should, because "user.json" file is still valid and has a valid token needed for authorization of the browser.
storageState fixture for some reason not set the authorization based on the file content, despite file is 100% valid
This application has only token-based authorization without cookies at all.
Try adding storage state to your setup project as well, see if it helps:
"projects":[
{
"name":"setup",
"testMatch":"auth.setup.ts",
"use":{
"storageState":".auth/user.json"
},
},
{
"name":"chromium",
"use":{
"...devices"[
"Desktop Chrome"
],
"storageState":".auth/user.json"
},
"dependencies":[
"setup"
]
}
]
global-setup works as expected. When test open up the URL, it goes back to the login page. I am not sure what I am doing wrong in my code. Can someone please help.
Playwright config file:
global setup:
test file: