@@ -108,14 +108,39 @@ Save console logs on a page to the specified file.
108
108
await saveConsoleLogs (page, ' logs.txt' );
109
109
```
110
110
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
+
111
133
[ browser ] : https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browser ' browser '
112
134
[ browsercontext ] : https://github.com/microsoft/playwright/blob/master/docs/api.md#class-browsercontext ' BrowserContext '
113
135
[ browsertype.launch ] : https://github.com/microsoft/playwright/blob/master/docs/api.md#browsertypelaunchoptions ' browserType.launch '
114
136
[ 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 '
115
139
[ object ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object ' Object '
116
140
[ page ] : https://github.com/microsoft/playwright/blob/master/docs/api.md#class-page ' Page '
117
141
[ page.evaluate ] : https://github.com/microsoft/playwright/blob/master/docs/api.md#pageevaluatepagefunction-args ' page.evaluate '
118
142
[ page.addinitscript ] : https://github.com/microsoft/playwright/blob/master/docs/api.md#pageaddinitscriptscript-args ' page.addInitScript '
119
143
[ promise ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise ' Promise '
120
144
[ 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 '
121
146
[ string ] : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#String_type ' String '
0 commit comments