Despite diligently following the instructions on the official Playwright page to configure the storageState feature, I am disappointed to discover that nothing is actually being saved:
The process I followed is outlined below:
(1) First, I created the global-setup.ts file:
async function globalSetup() {
const requestContext = await request.newContext();
let foo = await requestContext
.post('https://some/page/signin', {
form: {
'username': 'xxx',
'password': 'yyy',
'remember': 'on'
}
});
// The signed-in state should be saved to 'storageState.json'.
await requestContext.storageState({ path: 'storageState.json' });
await requestContext.dispose();
}
export default globalSetup;
(2) Next, I referenced the storageState in the playwright.config.ts file:
import { PlaywrightTestConfig } from '@playwright/test'
const config: PlaywrightTestConfig = {
globalSetup: require.resolve('./global-setup'),
timeout: 60000,
retries: 0,
use: {
// Instruct all tests to load the signed-in state from 'storageState.json'.
storageState: 'storageState.json',
headless: false,
viewport: { width: 1280, height: 720 },
actionTimeout: 15000,
ignoreHTTPSErrors: true,
video: 'retain-on-failure',
screenshot: 'only-on-failure',
},
projects: [
{
name: 'Chromium',
use: { browserName: 'chromium' },
}
],
}
export default config
However, upon inspecting the storageState.json file that was generated, I observed the following:
{
"cookies": [],
"origins": []
}
I can't seem to figure out why the cookies and origins data are empty, especially considering that the request returned a successful 200 response. What could be causing this issue?