Skip to content

Commit

Permalink
Fixed #2975 - expect.element() not present error (#2977)
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavsingh97 authored Feb 7, 2022
1 parent a16584c commit ed04684
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
9 changes: 1 addition & 8 deletions lib/api/expect/assertions/element/present.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@ class PresentAssertion extends BaseAssertion {
}

onResultFailed() {
if (this.resultErrorStatus instanceof Error) {
this.passed = false;
this.actual = 'error while locating the element';
this.expected = this.negate ? 'not present' : 'present';

return;
}

this.expected = this.negate ? 'not present' : 'present';
this.passed = this.negate;
}

Expand Down
24 changes: 23 additions & 1 deletion test/src/api/expect/testExpectPresent.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ describe('expect.present', function() {
assert.strictEqual(expect.assertion.waitForMs, 40);
assert.strictEqual(expect.assertion.passed, false);
assert.strictEqual(expect.assertion.expected, 'present');
assert.strictEqual(expect.assertion.actual, 'error while locating the element');
assert.strictEqual(expect.assertion.actual, 'not present');
assert.ok(expect.assertion.message.startsWith('Expected element <#weblogin> to be present - element was not found'));
assert.strictEqual(expect.assertion.messageParts[0], ' - element was not found');
});
Expand Down Expand Up @@ -170,6 +170,28 @@ describe('expect.present', function() {
});
});

it('to not be present if element doesn\'t exist [PASSED]', function() {
this.client.api.globals.waitForConditionTimeout = 40;
this.client.api.globals.waitForConditionPollInterval = 20;

Nocks.elementNotFound()
.elementNotFound()
.elementNotFound();

let expect = this.client.api.expect.element('#weblogin').to.not.be.present;

return this.client.start(function() {
assert.strictEqual(expect.assertion.selector, '#weblogin');
assert.strictEqual(expect.assertion.negate, true);
assert.strictEqual(expect.assertion.passed, true);
assert.strictEqual(expect.assertion.expected, 'not present');
assert.strictEqual(expect.assertion.actual, 'not present');
assert.strictEqual(expect.assertion.resultErrorStatus.name, 'NoSuchElementError');
assert.ok(expect.assertion.message.startsWith('Expected element <#weblogin> to not be present'));
assert.strictEqual(expect.assertion.messageParts.length, 2);
});
});

it('to be present - xpath via useXpath [PASSED]', function() {
Nocks.elementFoundXpath();

Expand Down

0 comments on commit ed04684

Please sign in to comment.