From e43552bd55da9a0c18fd863136a32a0d605acee4 Mon Sep 17 00:00:00 2001 From: Mark Stacey Date: Mon, 10 Jul 2023 17:09:37 -0230 Subject: [PATCH] Eliminate redundant locator building (#19585) Our e2e test driver was building the locator object multiple times over in some cases. The `Locator` object is required by certain webdriver methods, but our driver methods all accept a "raw locator". This change avoids a few redundant calls, and makes it easier to improve the error message for a timeout failure (which will be done in a later PR). It also makes the code match the documentation/parameter names. --- test/e2e/webdriver/driver.js | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/test/e2e/webdriver/driver.js b/test/e2e/webdriver/driver.js index 2c222ae95..ca8b9947d 100644 --- a/test/e2e/webdriver/driver.js +++ b/test/e2e/webdriver/driver.js @@ -161,16 +161,18 @@ class Driver { // replacement for the implementation below. It takes an option options // bucket that can include the state attribute to wait for elements that // match the selector to be removed from the DOM. - const selector = this.buildLocator(rawLocator); let element; if (!['visible', 'detached'].includes(state)) { throw new Error(`Provided state selector ${state} is not supported`); } if (state === 'visible') { - element = await this.driver.wait(until.elementLocated(selector), timeout); + element = await this.driver.wait( + until.elementLocated(this.buildLocator(rawLocator)), + timeout, + ); } else if (state === 'detached') { element = await this.driver.wait( - until.stalenessOf(await this.findElement(selector)), + until.stalenessOf(await this.findElement(rawLocator)), timeout, ); } @@ -205,15 +207,13 @@ class Driver { } async findVisibleElement(rawLocator) { - const locator = this.buildLocator(rawLocator); - const element = await this.findElement(locator); + const element = await this.findElement(rawLocator); await this.driver.wait(until.elementIsVisible(element), this.timeout); return wrapElementWithAPI(element, this); } async findClickableElement(rawLocator) { - const locator = this.buildLocator(rawLocator); - const element = await this.findElement(locator); + const element = await this.findElement(rawLocator); await Promise.all([ this.driver.wait(until.elementIsVisible(element), this.timeout), this.driver.wait(until.elementIsEnabled(element), this.timeout), @@ -231,8 +231,7 @@ class Driver { } async findClickableElements(rawLocator) { - const locator = this.buildLocator(rawLocator); - const elements = await this.findElements(locator); + const elements = await this.findElements(rawLocator); await Promise.all( elements.reduce((acc, element) => { acc.push( @@ -246,14 +245,12 @@ class Driver { } async clickElement(rawLocator) { - const locator = this.buildLocator(rawLocator); - const element = await this.findClickableElement(locator); + const element = await this.findClickableElement(rawLocator); await element.click(); } async clickPoint(rawLocator, x, y) { - const locator = this.buildLocator(rawLocator); - const element = await this.findElement(locator); + const element = await this.findElement(rawLocator); await this.driver .actions() .move({ origin: element, x, y }) @@ -281,10 +278,9 @@ class Driver { } async assertElementNotPresent(rawLocator) { - const locator = this.buildLocator(rawLocator); let dataTab; try { - dataTab = await this.findElement(locator); + dataTab = await this.findElement(rawLocator); } catch (err) { assert( err instanceof webdriverError.NoSuchElementError ||