This thread is trying to answer question "Why is the storage state generated in global setup not applied to the browser context for test cases sometimes in CI?"
Related Ask AI answer for "What are the reasons for the storage state generated in global setup not being applied to the browser context for test cases in CI?".
You might be wondering why the storage state you generated in the global setup isn't being applied to the browser context for your test cases in CI. There could be a few reasons for this.
Let's say you have two projects: 'logged in chromium' and 'logged out chromium'. The 'logged in chromium' project depends on the setup project and uses the storageState
option to apply the storage state on its browser context. But if a test case belongs to the 'logged out chromium' project, which doesn't depend on the setup project or use the storageState
option, it won't have access to the stored state.
If you want traces or artifacts from your tests, you should use project dependencies instead of globalSetup
and globalTeardown
. These methods don't produce such outputs.
Your configuration file (playwright.config.ts
) should correctly specify globalSetup
along with baseURL
and storageState
options. If these are incorrectly specified or missing, tests might start without being authenticated because they lack access to the populated storageState
from global setup.
Here's an example of a correctly specified configuration file:
import { PlaywrightTestConfig } from '@playwright/test';
const config: PlaywrightTestConfig = {
baseURL: 'https://ray.run',
globalSetup: './global-setup.ts',
projects: [
{
name: 'Chromium',
use: {
browserName: 'chromium',
storageState: './storage-state.json'
},
},
],
};
export default config;
So, make sure you're using dependencies correctly and specifying necessary options in your configuration file. This will ensure all test cases have access to the stored state generated during global setup.
Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].