Skip to content

Conversation

Samuel-StO
Copy link
Contributor

This PR introduces a new storageState option in the Playwright helper configuration.
With this change, users can pass a Playwright storage state directly (either as a path to a JSON file or as an object) to initialize browser contexts with preloaded session data such as cookies, localStorage, IndexedDB, or authentication tokens.

Key points

  • storageState can be configured globally in codecept.conf.js or overridden per scenario.
  • Ensures Playwright handles storage state validation and errors natively.
  • Simplifies authentication and session reuse across tests.

Applicable helpers:

  • Playwright
  • Puppeteer
  • WebDriver
  • REST
  • FileHelper
  • Appium
  • TestCafe

Applicable plugins:

  • allure
  • autoDelay
  • autoLogin
  • customLocator
  • pauseOnFail
  • coverage
  • retryFailedStep
  • screenshotOnFail
  • selenoid
  • stepByStepReport
  • stepTimeout
  • wdio
  • subtitles

Type of change

  • 🔥 Breaking changes
  • 🚀 New functionality
  • 🐛 Bug fix
  • 🧹 Chore
  • 📋 Documentation changes/updates
  • ♨️ Hot fix
  • 🔨 Markdown files fix - not related to source code
  • 💅 Polish code

Checklist:

  • Tests have been added
  • Documentation has been added (Run npm run docs)
  • Lint checking (Run npm run lint)
  • Local tests are passed (Run npm test)

@kobenguyent kobenguyent requested a review from Copilot September 23, 2025 08:48
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for Playwright's native storageState configuration to the Playwright helper, enabling users to initialize browser contexts with preloaded session data such as cookies, localStorage, and authentication tokens. The feature allows passing either a file path to a JSON storage state or a storage state object directly.

  • Adds storageState configuration option to Playwright helper
  • Implements grabStorageState() method to capture current browser state
  • Ensures scenario-level cookies override global storageState configuration

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
lib/helper/Playwright.js Adds storageState config handling and grabStorageState method
test/helper/Playwright_test.js Comprehensive test coverage for storageState functionality
docs/playwright.md User guide documentation with examples and security warnings
docs/helpers/Playwright.md API reference documentation for new features

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +1355 to +1362
* `options.indexedDB` **[boolean][26]?** set to true to include IndexedDB in snapshot (Playwright >=1.51)```js
// basic usage
const state = await I.grabStorageState();
require('fs').writeFileSync('authState.json', JSON.stringify(state));

// include IndexedDB when using Firebase Auth, etc.
const stateWithIDB = await I.grabStorageState({ indexedDB: true });
```
Copy link
Preview

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code block formatting is broken. The opening backticks should be on a new line after the parameter description, not inline with it.

Suggested change
* `options.indexedDB` **[boolean][26]?** set to true to include IndexedDB in snapshot (Playwright >=1.51)```js
// basic usage
const state = await I.grabStorageState();
require('fs').writeFileSync('authState.json', JSON.stringify(state));
// include IndexedDB when using Firebase Auth, etc.
const stateWithIDB = await I.grabStorageState({ indexedDB: true });
```
* `options.indexedDB` **[boolean][26]?** set to true to include IndexedDB in snapshot (Playwright >=1.51)
```js
// basic usage
const state = await I.grabStorageState();
require('fs').writeFileSync('authState.json', JSON.stringify(state));
// include IndexedDB when using Firebase Auth, etc.
const stateWithIDB = await I.grabStorageState({ indexedDB: true });
```

Copilot uses AI. Check for mistakes.

Comment on lines 606 to +608
// load pre-saved cookies
if (test?.opts?.cookies) contextOptions.storageState = { cookies: test.opts.cookies }

if (this.storageState) contextOptions.storageState = this.storageState
else if (this.storageState) contextOptions.storageState = this.storageState
Copy link
Preview

Copilot AI Sep 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The logic for handling storageState and cookies should be more explicit. Consider extracting this into a separate method or adding a comment explaining why scenario cookies completely override storageState rather than merging.

Copilot uses AI. Check for mistakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant