Skip to content

Commit

Permalink
fix #3571: return correct status code for waitForElementNotPresent (#…
Browse files Browse the repository at this point in the history
…3678)

* fix #3571; return correct status code for waitForElementNotPresent

*
---------

Co-authored-by: Harshit Agrawal <harshit.a@browserstack.com>
Co-authored-by: Harshit Agrawal <94462364+harshit-bs@users.noreply.github.com>
Co-authored-by: Binayak Ghosh <ghoshbinayak@gmail.com>

* update tests

* Revert "Feat/rerun (#3703)"

This reverts commit 020601e.

* revert and skip hasAttribute test

* refactor tests

---------

Co-authored-by: Prudhvi <prudhvi@browserstack.com>
Co-authored-by: Harshit Agrawal <harshit.a@browserstack.com>
Co-authored-by: Harshit Agrawal <94462364+harshit-bs@users.noreply.github.com>
  • Loading branch information
4 people authored and AutomatedTester committed May 16, 2023
1 parent 456af87 commit a928f65
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 10 deletions.
2 changes: 2 additions & 0 deletions lib/api/element-commands/waitForElementNotPresent.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,14 @@ class WaitForElementNotPresent extends WaitForElement {
*/
elementFound(result) {
let defaultMsg = 'Timed out while waiting for element <%s> to be removed for %d milliseconds.';
result.passed = false;

return this.fail(result, 'found', this.expectedValue, defaultMsg);
}

elementNotFound(result) {
let defaultMsg = 'Element <%s> was not present after %d milliseconds.';
result.passed = true;

return this.pass(result, defaultMsg, this.executor.elapsedTime);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/reporter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ class Reporter extends SimplifiedReporter {
try {
let commandResult = result;

const isSuccess = result === undefined ||
result == null ||
let isSuccess = result === undefined ||
result == null || result.passed ||
!((result instanceof Error) ||
(result.error instanceof Error) ||
result.status === -1
Expand Down
5 changes: 0 additions & 5 deletions test/lib/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,6 @@ class Globals {
}

client.queue.tree.empty().createRootNode();
client.queue.once('queue:finished', err => {
if (err) {
reject(err);
}
});

client.isES6AsyncTestcase = true;

Expand Down
18 changes: 18 additions & 0 deletions test/sampletests/withwait/elementNotPresent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
before(client) {
client.globals.calls++;
},

demoTest(client) {
client.url('http://localhost')
.waitForElementNotPresent('#badElement')
.waitForElementNotPresent('#weblogin')
.end();
},

after(client, callback) {
client.globals.calls++;
callback();
}
};

5 changes: 2 additions & 3 deletions test/src/api/commands/element/testSubmitForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ describe('submitForm', function() {
url: '/wd/hub/session/1352110219202/element/0/submit',
method: 'POST',
response: JSON.stringify({
sessionId: '1352110219202',
status: 0
})
value: null
}, true, true)
});

this.client.api.submitForm('#weblogin', function callback(result) {
Expand Down
41 changes: 41 additions & 0 deletions test/src/api/commands/element/testWaitForElementNotPresent.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
const path = require('path');
const assert = require('assert');
const CommandGlobals = require('../../../../lib/globals/commands.js');
const {strictEqual} = assert;
const common = require('../../../../common.js');
const {settings} = common;
const NightwatchClient = common.require('index.js');
const MockServer = require('../../../../lib/mockserver.js');


describe('waitForElementNotPresent', function () {
let commandResult;
Expand Down Expand Up @@ -73,4 +79,39 @@ describe('waitForElementNotPresent', function () {
strictEqual(commandInstance.rescheduleInterval, 10);
});
});


it('client.waitForElementNotPresent() report should not contain error in case of success', async function() {
MockServer.addMock({
url: '/wd/hub/session/1352110219202/elements',
method: 'POST',
postdata: {
using: 'css selector',
value: '#badElement'
},
response: JSON.stringify({
value: []
}),
times: 2
});

const testsPath = [
path.join(__dirname, '../../../../sampletests/withwait/elementNotPresent.js')
];

const globals = {
calls: 0,
reporter(results) {
assert.strictEqual(globals.calls, 2);
assert.strictEqual(Object.keys(results.modules).length, 1);
assert.ok('elementNotPresent' in results.modules);
assert.strictEqual(results.modulesWithEnv.default.elementNotPresent.completedSections.demoTest.commands[1].status, 'pass');
assert.strictEqual(results.modulesWithEnv.default.elementNotPresent.completedSections.demoTest.commands[2].status, 'fail');
}
};

await NightwatchClient.runTests(testsPath, settings({
globals
}));
});
});

0 comments on commit a928f65

Please sign in to comment.