Skip to content

Commit 311bb40

Browse files
committed
fix(typings): return types of grab methods
The JSDoc of several grab methods declared void, any, a plain array or StepPromise, so awaiting them failed type-aware linting and a missing await went unnoticed. WebDriver's grabBrowserLogs() always returns an array, like the other helpers. Refs #5806
1 parent 7817c93 commit 311bb40

8 files changed

Lines changed: 19 additions & 11 deletions

‎docs/webapi/grabBrowserLogs.mustache‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ let logs = await I.grabBrowserLogs();
66
console.log(JSON.stringify(logs))
77
```
88

9-
@returns {Promise<object[]>|undefined} all browser logs
9+
@returns {Promise<any[]>} all browser logs

‎docs/webapi/grabCookie.mustache‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ assert(cookie.value, '123456');
88
```
99

1010
@param {?string} [name=null] cookie name.
11-
@returns {any} attribute value
11+
@returns {Promise<any>} cookie object, or all cookies if no name is given

‎docs/webapi/grabDataFromPerformanceTiming.mustache‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ let data = await I.grabDataFromPerformanceTiming();
1717
loadEventEnd: 241
1818
}
1919
```
20-
@returns {CodeceptJS.StepPromise} automatically synchronized promise through #recorder
20+
@returns {Promise<{responseEnd: number, domInteractive: number, domContentLoadedEventEnd: number, loadEventEnd: number}>} performance timing data in ms

‎docs/webapi/grabRecordedNetworkTraffics.mustache‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ expect(traffics[0].response.status).to.equal(200);
77
expect(traffics[0].response.body).to.contain({ name: 'this was mocked' });
88
```
99

10-
@return { Array } recorded network traffics
10+
@returns {Promise<any[]>} recorded network traffics

‎lib/helper/Playwright.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2656,6 +2656,8 @@ class Playwright extends Helper {
26562656
* // include IndexedDB when using Firebase Auth, etc.
26572657
* const stateWithIDB = await I.grabStorageState({ indexedDB: true });
26582658
* ```
2659+
*
2660+
* @returns {Promise<object>} storage state
26592661
*/
26602662
async grabStorageState(options = {}) {
26612663
return this.browserContext.storageState(options)
@@ -4065,7 +4067,7 @@ class Playwright extends Helper {
40654067
* ```
40664068
*
40674069
* @param {string|RegExp} urlMatch Expected URL of request in network traffic. Can be a string or a regular expression.
4068-
* @return {Promise<*>}
4070+
* @return {Promise<string>}
40694071
*/
40704072
grabTrafficUrl(urlMatch) {
40714073
if (!this.recordedAtLeastOnce) {

‎typings/tests/helpers/Playwright.types.ts‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ expectType<CodeceptJS.StepPromise>(playwright.seeNumberOfVisibleElements(str, nu
9595
expectType<CodeceptJS.StepPromise>(playwright.setCookie({ name: str, value: str }));
9696
expectType<CodeceptJS.StepPromise>(playwright.seeCookie(str));
9797
expectType<CodeceptJS.StepPromise>(playwright.dontSeeCookie(str));
98-
expectType<any>(playwright.grabCookie());
98+
expectType<Promise<any>>(playwright.grabCookie());
99+
expectType<Promise<object>>(playwright.grabStorageState());
99100
expectType<void>(playwright.clearCookie());
100101
expectType<Promise<any>>(playwright.executeScript(() => {}));
101102
expectType<Promise<string>>(playwright.grabTextFrom(str));
@@ -132,12 +133,14 @@ expectType<CodeceptJS.StepPromise>(playwright.switchTo());
132133
expectType<CodeceptJS.StepPromise>(playwright.waitForFunction(() => { }));
133134
expectType<void>(playwright.waitForNavigation(str));
134135
expectType<CodeceptJS.StepPromise>(playwright.waitForDetached(str));
135-
expectType<CodeceptJS.StepPromise>(playwright.grabDataFromPerformanceTiming());
136+
expectType<Promise<{ responseEnd: number; domInteractive: number; domContentLoadedEventEnd: number; loadEventEnd: number }>>(playwright.grabDataFromPerformanceTiming());
136137
//expectType<Promise<number>>(playwright.grabElementBoundingRect(str));
137138
expectType<void>(playwright.mockRoute(str));
138139
expectType<void>(playwright.stopMockingRoute(str));
139140

140141
expectType<CodeceptJS.StepPromise>(playwright.startRecordingTraffic());
142+
expectType<Promise<string>>(playwright.grabTrafficUrl(str));
143+
expectType<Promise<any[]>>(playwright.grabRecordedNetworkTraffics());
141144
expectType<void>(playwright.stopRecordingTraffic());
142145
expectError(playwright.seeTraffic());
143146
expectError(playwright.seeTraffic(str));

‎typings/tests/helpers/PlaywrightTs.types.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ expectType<CodeceptJS.StepPromise>(playwright.setCookie({ name: str, value: str
9494
expectType<CodeceptJS.StepPromise>(playwright.seeCookie(str));
9595
expectType<CodeceptJS.StepPromise>(playwright.dontSeeCookie(str));
9696
expectType<Promise<any>>(playwright.grabCookie());
97+
expectType<Promise<object>>(playwright.grabStorageState());
9798
expectType<Promise<any>>(playwright.clearCookie());
9899
expectType<Promise<any>>(playwright.executeScript(() => {}));
99100
expectType<Promise<string>>(playwright.grabTextFrom(str));
@@ -130,12 +131,14 @@ expectType<CodeceptJS.StepPromise>(playwright.switchTo());
130131
expectType<CodeceptJS.StepPromise>(playwright.waitForFunction(() => { }));
131132
expectType<Promise<any>>(playwright.waitForNavigation(str));
132133
expectType<CodeceptJS.StepPromise>(playwright.waitForDetached(str));
133-
expectType<CodeceptJS.StepPromise>(playwright.grabDataFromPerformanceTiming());
134+
expectType<Promise<{ responseEnd: number; domInteractive: number; domContentLoadedEventEnd: number; loadEventEnd: number }>>(playwright.grabDataFromPerformanceTiming());
134135
//expectType<Promise<number>>(playwright.grabElementBoundingRect(str));
135136
expectType<Promise<any>>(playwright.mockRoute(str));
136137
expectType<Promise<any>>(playwright.stopMockingRoute(str));
137138

138139
expectType<CodeceptJS.StepPromise>(playwright.startRecordingTraffic());
140+
expectType<Promise<string>>(playwright.grabTrafficUrl(str));
141+
expectType<Promise<any[]>>(playwright.grabRecordedNetworkTraffics());
139142
expectType<Promise<any>>(playwright.stopRecordingTraffic());
140143
expectError(playwright.seeTraffic());
141144
expectError(playwright.seeTraffic(str));

‎typings/tests/helpers/WebDriverIO.types.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -450,15 +450,15 @@ expectType<Promise<string>>(wd.grabTitle())
450450

451451
expectType<Promise<string>>(wd.grabSource())
452452

453-
wd.grabBrowserLogs() // $ExpectType Promise<object[]> | undefined
453+
expectType<Promise<any[]>>(wd.grabBrowserLogs())
454454

455455
expectType<Promise<string>>(wd.grabCurrentUrl())
456456

457457
expectError(wd.grabNumberOfVisibleElements())
458458
expectType<Promise<number>>(wd.grabNumberOfVisibleElements('div'))
459459

460-
wd.grabCookie() // $ExpectType any
461-
wd.grabCookie('name') // $ExpectType any
460+
expectType<Promise<any>>(wd.grabCookie())
461+
expectType<Promise<any>>(wd.grabCookie('name'))
462462

463463
expectType<Promise<string>>(wd.grabPopupText())
464464

0 commit comments

Comments
 (0)