Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NoSuchElementError suppressed in assert.not.present() #4345

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions lib/api/web-element/assert/element-assertions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
const {WebElement} = require('selenium-webdriver');

class ScopedElementAssertions {
constructor(scopedElement, {negated, nightwatchInstance}) {
constructor(scopedElement, {negated, nightwatchInstance}, suppressNotFoundErrors = false) {
this.negated = negated;
this.scopedElement = scopedElement;
this.scopedElement.suppressNotFoundErrors = suppressNotFoundErrors;
this.nightwatchInstance = nightwatchInstance;
}

set suppressNotFoundErrors(value){
this.scopedElement.suppressNotFoundErrors = value;
}

assert(callback) {
// The below promise is returned to the test case by the assertion, so
// it should fail in case the actual assertion (callback) fails. In case
Expand Down Expand Up @@ -41,19 +46,19 @@ class ScopedElementAssertions {
}
}

module.exports.create = function createAssertions(scopedElement, {negated = false, nightwatchInstance}) {
module.exports.create = function createAssertions(scopedElement, {negated = false, nightwatchInstance}, suppressNotFoundErrors = false) {
const instance = new ScopedElementAssertions(scopedElement, {
negated,
nightwatchInstance
});
}, suppressNotFoundErrors);

const exported = {};
Object.defineProperty(exported, 'not', {
get() {
return createAssertions(scopedElement, {
negated: true,
nightwatchInstance
});
}, suppressNotFoundErrors = true);
}
});

Expand Down Expand Up @@ -88,6 +93,8 @@ module.exports.create = function createAssertions(scopedElement, {negated = fals
},
present: {
value(message) {
instance.suppressNotFoundErrors = true;

return instance.assert(async (assertApi, element) => {
const el = await element;
const id = await el.getId();
Expand Down
4 changes: 4 additions & 0 deletions lib/api/web-element/scoped-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ class ScopedWebElement {
return this._suppressNotFoundErrors;
}

set suppressNotFoundErrors(value) {
this._suppressNotFoundErrors = value;
}

constructor(selector = 'html', parentElement, nightwatchInstance) {
this.nightwatchInstance = nightwatchInstance;
this.parentScopedElement = parentElement;
Expand Down
Loading