From 030e87c119e209bc3fc4e97cc8c8a48554e32ef8 Mon Sep 17 00:00:00 2001 From: Alfred Westerveld Date: Fri, 5 Aug 2022 16:45:00 +0200 Subject: [PATCH] test run locally first --- .../src/DullahanAdapterSelenium4.ts | 101 +++++------------- 1 file changed, 25 insertions(+), 76 deletions(-) diff --git a/packages/dullahan-adapter-selenium-4/src/DullahanAdapterSelenium4.ts b/packages/dullahan-adapter-selenium-4/src/DullahanAdapterSelenium4.ts index 49a152a3a..13d3fb056 100644 --- a/packages/dullahan-adapter-selenium-4/src/DullahanAdapterSelenium4.ts +++ b/packages/dullahan-adapter-selenium-4/src/DullahanAdapterSelenium4.ts @@ -1,6 +1,6 @@ import {Agent} from 'https'; -import {Builder, Origin, until, WebDriver, WebElement, Key} from 'selenium-webdriver'; +import {Builder, Origin, until, WebDriver, WebElement, Key, By} from 'selenium-webdriver'; import { buildChrome, @@ -32,12 +32,9 @@ import { getElementAttributes, getElementProperties, getElementStyles, - scrollToElement, setElementAttribute, setElementProperty, - sleep, tryIgnore, - tryX, waitForReadyState } from '@k2g/dullahan'; @@ -1192,29 +1189,19 @@ export default class DullahanAdapterSelenium4 extends DullahanAdapter { - const {driver, supportsPromises} = this; + const { driver, options } = this; if (!driver) { throw new AdapterError(DullahanErrorMessage.NO_BROWSER); } - const findOptions: FindElementOptions = { - selector, - visibleOnly: false, - onScreenOnly: false, - interactiveOnly: false, - timeout: 200, - promise: supportsPromises, - expectNoMatches: false - }; - - const element = await driver.executeScript(findElement, findOptions); + const locatedElement = this.locateElement(selector); + const element = await driver.wait(until.elementLocated(locatedElement), 1000); if (!element) { - throw new AdapterError(DullahanErrorMessage.findElementResult(findOptions)); + throw new AdapterError(`Could not scroll to element ${selector}`); } - - await driver.executeScript(scrollToElement, element); + await driver.executeScript("arguments[0].scrollIntoView()", element); } public async screenshotPage(): Promise { @@ -1263,29 +1250,14 @@ export default class DullahanAdapterSelenium4 extends DullahanAdapter driver.executeScript(findElement, findOptions), timeout || 1); - + const locatedElement = this.locateElement(selector); + const element = await driver.wait(until.elementLocated(locatedElement), timeout); + if (!element) { - throw new AdapterError(DullahanErrorMessage.findElementResult(findOptions)); + throw new AdapterError(`Unable to find element ${selector}`); } } catch (error: any) { - if (error.name === 'TimeoutError') { - throw new AdapterError(DullahanErrorMessage.findElementResult(findOptions)); - } else if (/unloaded|destroyed/ui.test(error.message)) { - return this.waitForElementPresent(selector, options); - } - throw error; } } @@ -1300,29 +1272,14 @@ export default class DullahanAdapterSelenium4 extends DullahanAdapter driver.executeScript(findElement, findOptions), timeout || 1); - + const locatedElement = this.locateElement(selector); + const element = await driver.wait(until.elementIsVisible(driver.findElement(locatedElement)), timeout || 0); + if (!element) { - throw new AdapterError(DullahanErrorMessage.findElementResult(findOptions)); + throw new AdapterError(`Unable to find element ${selector}`); } } catch (error: any) { - if (error.name === 'TimeoutError') { - throw new AdapterError(DullahanErrorMessage.findElementResult(findOptions)); - } else if (/unloaded|destroyed/ui.test(error.message)) { - return this.waitForElementVisible(selector, options); - } - throw error; } } @@ -1337,29 +1294,15 @@ export default class DullahanAdapterSelenium4 extends DullahanAdapter driver.executeScript(findElement, findOptions), timeout || 1); - + const locatedElement = this.locateElement(selector); + const element = await driver.wait(until.elementLocated(locatedElement), timeout); + await this.scrollToElement(selector); + if (!element) { - throw new AdapterError(DullahanErrorMessage.findElementResult(findOptions)); + throw new AdapterError(`Unable to interact with element ${selector}`); } } catch (error: any) { - if (error.name === 'TimeoutError') { - throw new AdapterError(DullahanErrorMessage.findElementResult(findOptions)); - } else if (/unloaded|destroyed/ui.test(error.message)) { - return this.waitForElementInteractive(selector, options); - } - throw error; } } @@ -1467,4 +1410,10 @@ export default class DullahanAdapterSelenium4 extends DullahanAdapter