You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: Add support for Playwright storageState configuration (#5192)
* feat: add support for Playwright storageState configuration and helper methods
* doc : run docs
---------
Co-authored-by: kobenguyent <kobenguyent@gmail.com>
Copy file name to clipboardExpand all lines: docs/playwright.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -664,3 +664,48 @@ Playwright can be added to GitHub Actions using [official action](https://github
664
664
- name: run CodeceptJS tests
665
665
run: npx codeceptjs run
666
666
```
667
+
668
+
## Reusing Auth State (storageState) <Badge text="Since 3.7.5" type="warning"/>
669
+
670
+
Use Playwright's native `storageState` to start tests already authenticated.
671
+
Pass either a JSON file path or a state object to the Playwright helper; CodeceptJS forwards it directly to Playwright (no pre-checks).
672
+
673
+
**Sensitive**: A storage state contains session cookies, auth tokens and may contain localStorage / IndexedDB application data. Treat it like a secret: do not commit it to git, encrypt or store it in a secure CI artifact store.
**Limitation**: If a Scenario is declared with a `cookies` option (e.g. `Scenario('My test', { cookies: [...] }, ({ I }) => { ... })`), those cookies are used to initialize the context and any helper-level `storageState` is ignored (no merge). Choose one mechanism per Scenario.
Copy file name to clipboardExpand all lines: lib/helper/Playwright.js
+38-3Lines changed: 38 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,13 @@ const pathSeparator = path.sep
98
98
* @prop {boolean} [highlightElement] - highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose).
99
99
* @prop {object} [recordHar] - record HAR and will be saved to `output/har`. See more of [HAR options](https://playwright.dev/docs/api/class-browser#browser-new-context-option-record-har).
100
100
* @prop {string} [testIdAttribute=data-testid] - locate elements based on the testIdAttribute. See more of [locate by test id](https://playwright.dev/docs/locators#locate-by-test-id).
101
-
* @prop {object} [customLocatorStrategies] - custom locator strategies. An object with keys as strategy names and values as JavaScript functions. Example: `{ byRole: (selector, root) => { return root.querySelector(\`[role="\${selector}\"]\`) }}`
101
+
* @prop {object} [customLocatorStrategies] - custom locator strategies. An object with keys as strategy names and values as JavaScript functions. Example: `{ byRole: (selector, root) => { return root.querySelector(`[role="${selector}"]`) }}`
102
+
* @prop {string|object} [storageState] - Playwright storage state (path to JSON file or object)
103
+
* passed directly to `browser.newContext`.
104
+
* If a Scenario is declared with a `cookies` option (e.g. `Scenario('name', { cookies: [...] }, fn)`),
105
+
* those cookies are used instead and the configured `storageState` is ignored (no merge).
106
+
* May include session cookies, auth tokens, localStorage and (if captured with
107
+
* `grabStorageState({ indexedDB: true })`) IndexedDB data; treat as sensitive and do not commit.
102
108
*/
103
109
constconfig={}
104
110
@@ -360,6 +366,11 @@ class Playwright extends Helper {
360
366
// override defaults with config
361
367
this._setConfig(config)
362
368
369
+
// pass storageState directly (string path or object) and let Playwright handle errors/missing file
370
+
if(typeofconfig.storageState!=='undefined'){
371
+
this.storageState=config.storageState
372
+
}
373
+
363
374
}
364
375
365
376
_validateConfig(config){
@@ -386,6 +397,7 @@ class Playwright extends Helper {
386
397
use: {actionTimeout: 0},
387
398
ignoreHTTPSErrors: false,// Adding it here o that context can be set up to ignore the SSL errors,
388
399
highlightElement: false,
400
+
storageState: undefined,
389
401
}
390
402
391
403
process.env.testIdAttribute='data-testid'
@@ -589,8 +601,7 @@ class Playwright extends Helper {
0 commit comments