From 8dc430237120fd66e105219e63119239b24cee84 Mon Sep 17 00:00:00 2001 From: dprevost-perso Date: Mon, 26 Jan 2026 21:12:21 -0500 Subject: [PATCH 1/2] Fix bad elements refetch not passing the this browser context --- src/util/refetchElements.ts | 5 +++-- test/util/refetchElements.test.ts | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/util/refetchElements.ts b/src/util/refetchElements.ts index 2ee14a228..403c7539c 100644 --- a/src/util/refetchElements.ts +++ b/src/util/refetchElements.ts @@ -12,8 +12,9 @@ export const refetchElements = async ( full = false ): Promise => { if (elements && wait > 0 && (elements.length === 0 || full) && isElementArray(elements) && elements.parent && elements.foundWith && elements.foundWith in elements.parent) { - const fetchFunction = elements.parent[elements.foundWith as keyof typeof elements.parent] as Function - elements = await fetchFunction(elements.selector, ...elements.props) + const browser = elements.parent + const $$ = browser[elements.foundWith as keyof typeof browser] as Function + elements = await $$.call(browser, elements.selector, ...elements.props) } return elements } diff --git a/test/util/refetchElements.test.ts b/test/util/refetchElements.test.ts index 0f50e682b..d66984cf3 100644 --- a/test/util/refetchElements.test.ts +++ b/test/util/refetchElements.test.ts @@ -51,6 +51,20 @@ describe('refetchElements', () => { const actual = await refetchElements(elements, 0, true) expect(actual).toEqual(elements) }) + + test('should call $$ with all props', async () => { + elements.props = ['prop1', 'prop2'] + await refetchElements(elements, 5, true) + expect(elements.parent.$$).toHaveBeenCalledWith('parent', 'prop1', 'prop2') + }) + + test('should parent.foundWith using the proper this context', async () => { + const parentFoundWith = vi.mocked(elements.parent.$$) + + await refetchElements(elements, 5, true) + + expect(parentFoundWith.mock.contexts[0]).toBe(elements.parent) + }) }) describe('given WebdriverIO.Element[] type', () => { From db72b15249406477bd1e6197601e1dc6035d717f Mon Sep 17 00:00:00 2001 From: dprevost-perso Date: Mon, 26 Jan 2026 21:17:58 -0500 Subject: [PATCH 2/2] code review --- test/util/refetchElements.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/util/refetchElements.test.ts b/test/util/refetchElements.test.ts index d66984cf3..39543a0e8 100644 --- a/test/util/refetchElements.test.ts +++ b/test/util/refetchElements.test.ts @@ -58,7 +58,7 @@ describe('refetchElements', () => { expect(elements.parent.$$).toHaveBeenCalledWith('parent', 'prop1', 'prop2') }) - test('should parent.foundWith using the proper this context', async () => { + test('should call $$ with the proper parent this context', async () => { const parentFoundWith = vi.mocked(elements.parent.$$) await refetchElements(elements, 5, true)