(currentElement: WebdriverIO.Element, commandName: string)
| 9 | * - command is not explicit wait command for existance or displayedness |
| 10 | */ |
| 11 | export default async function implicitWait (currentElement: WebdriverIO.Element, commandName: string): Promise<WebdriverIO.Element> { |
| 12 | const browser = getBrowserObject(currentElement) |
| 13 | const skipForMobileScroll = browser.isMobile && await browser.isNativeContext && (commandName === 'scrollIntoView' || commandName === 'tap') |
| 14 | |
| 15 | if (!currentElement.elementId && !/(waitUntil|waitFor|isExisting|is?\w+Displayed|is?\w+Clickable)/.test(commandName) && !skipForMobileScroll) { |
| 16 | log.debug( |
| 17 | `command ${commandName} was called on an element ("${currentElement.selector}") ` + |
| 18 | 'that wasn\'t found, waiting for it...' |
| 19 | ) |
| 20 | |
| 21 | try { |
| 22 | await currentElement.waitForExist() |
| 23 | /** |
| 24 | * if waitForExist was successful requery element and assign elementId to the scope |
| 25 | */ |
| 26 | return (currentElement.parent as WebdriverIO.Element).$(currentElement.selector).getElement() |
| 27 | } catch { |
| 28 | if (currentElement.selector.toString().includes('this.previousElementSibling')) { |
| 29 | throw new Error( |
| 30 | `Can't call ${commandName} on previous element of element with selector "${(currentElement.parent as WebdriverIO.Element).selector}" because sibling wasn't found`) |
| 31 | } |
| 32 | |
| 33 | if (currentElement.selector.toString().includes('this.nextElementSibling')) { |
| 34 | throw new Error( |
| 35 | `Can't call ${commandName} on next element of element with selector "${(currentElement.parent as WebdriverIO.Element).selector}" because sibling wasn't found`) |
| 36 | } |
| 37 | |
| 38 | if (currentElement.selector.toString().includes('this.parentElement')) { |
| 39 | throw new Error( |
| 40 | `Can't call ${commandName} on parent element of element with selector "${(currentElement.parent as WebdriverIO.Element).selector}" because it wasn't found`) |
| 41 | } |
| 42 | |
| 43 | throw new Error( |
| 44 | `Can't call ${commandName} on element with selector "${currentElement.selector}" because element wasn't found`) |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | return currentElement |
| 49 | } |
no test coverage detected
searching dependent graphs…