From 7817c938676b37b04e01dc6497089b04dbd3581d Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Mon, 16 Nov 2026 10:40:36 +0100 Subject: [PATCH 1/2] fix(typings): add a result type to StepPromise StepPromise and ElementStepPromise extended Promise, so a helper step that returns data could not be declared with its result type, and declaration merging cannot add a type parameter. The default keeps every existing CodeceptJS.StepPromise as it is. Refs #5806 --- typings/index.d.ts | 4 ++-- typings/tests/helpers/Playwright.types.ts | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index 4f89989ec..a8bbbcc0a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -527,13 +527,13 @@ declare namespace CodeceptJS { type StringOrSecret = string | CodeceptJS.Secret - interface StepPromise extends Promise { + interface StepPromise extends Promise { stepConfig(config: CodeceptJS.StepConfig): this timeout(seconds: number): this retry(retry: number | object): this } - interface ElementStepPromise extends StepPromise { + interface ElementStepPromise extends StepPromise { first(): this last(): this at(position: number): this diff --git a/typings/tests/helpers/Playwright.types.ts b/typings/tests/helpers/Playwright.types.ts index c94c2b78a..f2baa79a6 100644 --- a/typings/tests/helpers/Playwright.types.ts +++ b/typings/tests/helpers/Playwright.types.ts @@ -1,4 +1,4 @@ -import { expectError, expectType } from 'tsd'; +import { expectAssignable, expectError, expectType } from 'tsd'; // @ts-ignore const playwright = new CodeceptJS.Playwright(); @@ -159,6 +159,13 @@ expectType(playwright.see(str).timeout(5)) expectType(playwright.see(str).retry(3)) expectType(playwright.click(str).first().timeout(5).retry(3)) +async function stepPromiseTypes(step: CodeceptJS.StepPromise, elementStep: CodeceptJS.ElementStepPromise) { + expectType(await step); + expectType>(step.timeout(5).retry(3)); + expectType(await elementStep.first().timeout(5)); + expectAssignable(step); +} + async function webElementTypes(el: CodeceptJS.WebElement) { expectType(await el.getText()); expectType(await el.getAttribute(str)); From 311bb40912fa7a3616cba22cf26e20f6eea5f6cd Mon Sep 17 00:00:00 2001 From: Daniel Rentz Date: Mon, 16 Nov 2026 10:40:37 +0100 Subject: [PATCH 2/2] 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 --- docs/webapi/grabBrowserLogs.mustache | 2 +- docs/webapi/grabCookie.mustache | 2 +- docs/webapi/grabDataFromPerformanceTiming.mustache | 2 +- docs/webapi/grabRecordedNetworkTraffics.mustache | 2 +- lib/helper/Playwright.js | 4 +++- typings/tests/helpers/Playwright.types.ts | 7 +++++-- typings/tests/helpers/PlaywrightTs.types.ts | 5 ++++- typings/tests/helpers/WebDriverIO.types.ts | 6 +++--- 8 files changed, 19 insertions(+), 11 deletions(-) diff --git a/docs/webapi/grabBrowserLogs.mustache b/docs/webapi/grabBrowserLogs.mustache index f504f2357..5ae064eb9 100644 --- a/docs/webapi/grabBrowserLogs.mustache +++ b/docs/webapi/grabBrowserLogs.mustache @@ -6,4 +6,4 @@ let logs = await I.grabBrowserLogs(); console.log(JSON.stringify(logs)) ``` -@returns {Promise|undefined} all browser logs +@returns {Promise} all browser logs diff --git a/docs/webapi/grabCookie.mustache b/docs/webapi/grabCookie.mustache index 3a40652ce..37f219810 100644 --- a/docs/webapi/grabCookie.mustache +++ b/docs/webapi/grabCookie.mustache @@ -8,4 +8,4 @@ assert(cookie.value, '123456'); ``` @param {?string} [name=null] cookie name. -@returns {any} attribute value +@returns {Promise} cookie object, or all cookies if no name is given diff --git a/docs/webapi/grabDataFromPerformanceTiming.mustache b/docs/webapi/grabDataFromPerformanceTiming.mustache index 3ea3041d0..51c3f52cc 100644 --- a/docs/webapi/grabDataFromPerformanceTiming.mustache +++ b/docs/webapi/grabDataFromPerformanceTiming.mustache @@ -17,4 +17,4 @@ let data = await I.grabDataFromPerformanceTiming(); loadEventEnd: 241 } ``` -@returns {CodeceptJS.StepPromise} automatically synchronized promise through #recorder +@returns {Promise<{responseEnd: number, domInteractive: number, domContentLoadedEventEnd: number, loadEventEnd: number}>} performance timing data in ms diff --git a/docs/webapi/grabRecordedNetworkTraffics.mustache b/docs/webapi/grabRecordedNetworkTraffics.mustache index 90cc824fb..97924a393 100644 --- a/docs/webapi/grabRecordedNetworkTraffics.mustache +++ b/docs/webapi/grabRecordedNetworkTraffics.mustache @@ -7,4 +7,4 @@ expect(traffics[0].response.status).to.equal(200); expect(traffics[0].response.body).to.contain({ name: 'this was mocked' }); ``` -@return { Array } recorded network traffics +@returns {Promise} recorded network traffics diff --git a/lib/helper/Playwright.js b/lib/helper/Playwright.js index d621eca17..01f9636cb 100644 --- a/lib/helper/Playwright.js +++ b/lib/helper/Playwright.js @@ -2656,6 +2656,8 @@ class Playwright extends Helper { * // include IndexedDB when using Firebase Auth, etc. * const stateWithIDB = await I.grabStorageState({ indexedDB: true }); * ``` + * + * @returns {Promise} storage state */ async grabStorageState(options = {}) { return this.browserContext.storageState(options) @@ -4065,7 +4067,7 @@ class Playwright extends Helper { * ``` * * @param {string|RegExp} urlMatch Expected URL of request in network traffic. Can be a string or a regular expression. - * @return {Promise<*>} + * @return {Promise} */ grabTrafficUrl(urlMatch) { if (!this.recordedAtLeastOnce) { diff --git a/typings/tests/helpers/Playwright.types.ts b/typings/tests/helpers/Playwright.types.ts index f2baa79a6..a74ff9e93 100644 --- a/typings/tests/helpers/Playwright.types.ts +++ b/typings/tests/helpers/Playwright.types.ts @@ -95,7 +95,8 @@ expectType(playwright.seeNumberOfVisibleElements(str, nu expectType(playwright.setCookie({ name: str, value: str })); expectType(playwright.seeCookie(str)); expectType(playwright.dontSeeCookie(str)); -expectType(playwright.grabCookie()); +expectType>(playwright.grabCookie()); +expectType>(playwright.grabStorageState()); expectType(playwright.clearCookie()); expectType>(playwright.executeScript(() => {})); expectType>(playwright.grabTextFrom(str)); @@ -132,12 +133,14 @@ expectType(playwright.switchTo()); expectType(playwright.waitForFunction(() => { })); expectType(playwright.waitForNavigation(str)); expectType(playwright.waitForDetached(str)); -expectType(playwright.grabDataFromPerformanceTiming()); +expectType>(playwright.grabDataFromPerformanceTiming()); //expectType>(playwright.grabElementBoundingRect(str)); expectType(playwright.mockRoute(str)); expectType(playwright.stopMockingRoute(str)); expectType(playwright.startRecordingTraffic()); +expectType>(playwright.grabTrafficUrl(str)); +expectType>(playwright.grabRecordedNetworkTraffics()); expectType(playwright.stopRecordingTraffic()); expectError(playwright.seeTraffic()); expectError(playwright.seeTraffic(str)); diff --git a/typings/tests/helpers/PlaywrightTs.types.ts b/typings/tests/helpers/PlaywrightTs.types.ts index b81d2e029..f284abba3 100644 --- a/typings/tests/helpers/PlaywrightTs.types.ts +++ b/typings/tests/helpers/PlaywrightTs.types.ts @@ -94,6 +94,7 @@ expectType(playwright.setCookie({ name: str, value: str expectType(playwright.seeCookie(str)); expectType(playwright.dontSeeCookie(str)); expectType>(playwright.grabCookie()); +expectType>(playwright.grabStorageState()); expectType>(playwright.clearCookie()); expectType>(playwright.executeScript(() => {})); expectType>(playwright.grabTextFrom(str)); @@ -130,12 +131,14 @@ expectType(playwright.switchTo()); expectType(playwright.waitForFunction(() => { })); expectType>(playwright.waitForNavigation(str)); expectType(playwright.waitForDetached(str)); -expectType(playwright.grabDataFromPerformanceTiming()); +expectType>(playwright.grabDataFromPerformanceTiming()); //expectType>(playwright.grabElementBoundingRect(str)); expectType>(playwright.mockRoute(str)); expectType>(playwright.stopMockingRoute(str)); expectType(playwright.startRecordingTraffic()); +expectType>(playwright.grabTrafficUrl(str)); +expectType>(playwright.grabRecordedNetworkTraffics()); expectType>(playwright.stopRecordingTraffic()); expectError(playwright.seeTraffic()); expectError(playwright.seeTraffic(str)); diff --git a/typings/tests/helpers/WebDriverIO.types.ts b/typings/tests/helpers/WebDriverIO.types.ts index c060ec589..c37206c50 100644 --- a/typings/tests/helpers/WebDriverIO.types.ts +++ b/typings/tests/helpers/WebDriverIO.types.ts @@ -450,15 +450,15 @@ expectType>(wd.grabTitle()) expectType>(wd.grabSource()) -wd.grabBrowserLogs() // $ExpectType Promise | undefined +expectType>(wd.grabBrowserLogs()) expectType>(wd.grabCurrentUrl()) expectError(wd.grabNumberOfVisibleElements()) expectType>(wd.grabNumberOfVisibleElements('div')) -wd.grabCookie() // $ExpectType any -wd.grabCookie('name') // $ExpectType any +expectType>(wd.grabCookie()) +expectType>(wd.grabCookie('name')) expectType>(wd.grabPopupText())