Skip to content

Commit

Permalink
Few refactors.
Browse files Browse the repository at this point in the history
  • Loading branch information
garg3133 committed Aug 12, 2024
1 parent 66faef3 commit 6595b0f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
3 changes: 2 additions & 1 deletion lib/api/web-element/commands/isPresent.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Checks if an element is present in the DOM.
*
* This command is useful for verifying the presence of elements that may not be visible or interactable.
*
* For more information on working with DOM elements in Nightwatch, refer to the <a href="https://nightwatchjs.org/guide/working-with-page-elements/finding-elements.html">Finding Elements</a> guide page.
*
* @example
Expand All @@ -18,7 +19,7 @@
* });
* });
*
* @since 3.5.0
* @since 3.7.1
* @method isPresent
* @memberof ScopedWebElement
* @instance
Expand Down
14 changes: 7 additions & 7 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,26 +161,22 @@ class ScopedWebElement {
return webElements[index];
}

async findElementAction({parentElement, condition, index, timeout, retryInterval, abortOnFailure, suppressNotFoundErrors}) {
async findElementAction({parentElement, condition, index, timeout, retryInterval, abortOnFailure}) {
const createAction = () => async ({args}) => {
if ((args[0] instanceof Promise) && !args[0]['@nightwatch_element']) {
args[0] = await args[0];
}

const parentElement = args[0];

if (suppressNotFoundErrors) {
this._suppressNotFoundErrors = true;
}

try {
if (condition.usingRecursion) {
return await this.findElementUsingRecursion({parentElement, recursiveElement: condition, timeout, retryInterval});
}

return await this.findElement({parentElement, selector: condition, index, timeout, retryInterval});
} catch (error) {
if (this._suppressNotFoundErrors) {
if (this.suppressNotFoundErrors) {
return null;
}

Expand Down Expand Up @@ -249,8 +245,12 @@ class ScopedWebElement {
return resolve(condition);
}

if (suppressNotFoundErrors) {
this._suppressNotFoundErrors = true;
}

const webElement = await this.findElementAction({
parentElement, condition, index, timeout, retryInterval, abortOnFailure, suppressNotFoundErrors
parentElement, condition, index, timeout, retryInterval, abortOnFailure
});

resolve(webElement);
Expand Down
1 change: 1 addition & 0 deletions lib/transport/selenium-webdriver/method-mappings.js
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ module.exports = class MethodMappings {
},

async isElementPresent(webElement) {
// webElement would be a Promise in case of new Element API.
const element = await webElement;

return element instanceof WebElement || element instanceof ShadowRoot;
Expand Down

0 comments on commit 6595b0f

Please sign in to comment.