Rayrun
← Back to Discord Forum

storage state issue

deadbeef01

We are getting a weird issue wherein the storage state generated in global setup is not applied to the browser context for test cases sometimes in CI. Which causes tests to fail randomly. We are using playwright 1.35 version. Does anyone else came across this .

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?"

0 replies

Answer

Why Your Storage State Might Not Apply

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.

Project Dependencies

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.

Global Setup and Teardown

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.

Configuration File

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.

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

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].