Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit 2eeb74a

Browse files
authored
Merge pull request #18 from qawolf/save-state
setState and saveState utils
2 parents 9ac7351 + b83c89a commit 2eeb74a

10 files changed

+2514
-693
lines changed

.github/workflows/test.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ jobs:
4242

4343
- run: npm run build
4444

45-
- run: npx @qawolf/sandbox &
45+
- run: npm run test:server &
4646
if: matrix.test != 'lint'
4747

48-
- run: QAW_BROWSER=${{ matrix.test }} npm test
48+
# TODO remove forceExit after https://github.com/qawolf/playwright-utils/issues/19
49+
- run: QAW_BROWSER=${{ matrix.test }} npm test -- --forceExit
4950
if: matrix.test != 'lint'
5051
env:
5152
CI: true

README.md

+25
Original file line numberDiff line numberDiff line change
@@ -108,14 +108,39 @@ Save console logs on a page to the specified file.
108108
await saveConsoleLogs(page, 'logs.txt');
109109
```
110110

111+
#### playwright-utils.saveState(page, savePath)
112+
113+
- `page` <[Page]> Save the state (cookies, [localStorage], [sessionStorage]) of this page.
114+
- `savePath` <[string]> Path where state will be saved as [JSON].
115+
116+
Save the state of a page (cookies, [localStorage], [sessionStorage]) to the specified file as [JSON].
117+
118+
```js
119+
await saveState(page, 'admin.json');
120+
```
121+
122+
#### playwright-utils.setState(page, savePath)
123+
124+
- `page` <[Page]> Apply the saved state (cookies, [localStorage], [sessionStorage]) to this page.
125+
- `savePath` <[string]> Path where state [JSON] is saved.
126+
127+
Sets the state of a page (cookies, [localStorage], [sessionStorage]) to the [JSON] saved in the specified path.
128+
129+
```js
130+
await setState(page, 'admin.json');
131+
```
132+
111133
[browser]: https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browser 'browser'
112134
[browsercontext]: https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browsercontext 'BrowserContext'
113135
[browsertype.launch]: https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypelaunchoptions 'browserType.launch'
114136
[function]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function 'Function'
137+
[json]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON 'JSON'
138+
[localstorage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage 'localStorage'
115139
[object]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object 'Object'
116140
[page]: https://github.com/microsoft/playwright/blob/master/docs/api.md#class-page 'Page'
117141
[page.evaluate]: https://github.com/microsoft/playwright/blob/master/docs/api.md#pageevaluatepagefunction-args 'page.evaluate'
118142
[page.addinitscript]: https://github.com/microsoft/playwright/blob/master/docs/api.md#pageaddinitscriptscript-args 'page.addInitScript'
119143
[promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise 'Promise'
120144
[serializable]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#Description 'Serializable'
145+
[sessionstorage]: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage 'sessionStorage'
121146
[string]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type 'String'

0 commit comments

Comments
 (0)