forked from webdriverio/expect-webdriverio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefetchElements.ts
More file actions
20 lines (19 loc) · 871 Bytes
/
refetchElements.ts
File metadata and controls
20 lines (19 loc) · 871 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import { DEFAULT_OPTIONS } from '../constants.js'
import type { WdioElements } from '../types.js'
import { isElementArray } from './elementsUtil.js'
/**
* Refetch elements array or return when elements is not of type WebdriverIO.ElementArray
* @param elements WebdriverIO.ElementArray | WebdriverIO.Element[]
*/
export const refetchElements = async (
elements: WdioElements,
wait = DEFAULT_OPTIONS.wait,
full = false
): Promise<WdioElements> => {
if (elements && wait > 0 && (elements.length === 0 || full) && isElementArray(elements) && elements.parent && elements.foundWith && elements.foundWith in elements.parent) {
const browser = elements.parent
const $$ = browser[elements.foundWith as keyof typeof browser] as Function
elements = await $$.call(browser, elements.selector, ...elements.props)
}
return elements
}