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 Nightwatch commands in waitUntil callback return NightwatchAPI instead of a Promise #4171

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/api/protocol/waitUntil.js
Expand Up @@ -65,6 +65,10 @@ module.exports = class WaitUntil extends ProtocolAction {
return true;
}

static get alwaysAsync() {
return true;
}

//timeMs, retryInterval, message, callback = function(r) {return r}
async command(conditionFn, ...args) {
let callback = function(r) {return r};
Expand Down
23 changes: 23 additions & 0 deletions test/src/api/commands/client/testWaitUntil.js
@@ -1,4 +1,5 @@
const assert = require('assert');
const MockServer = require('../../../../lib/mockserver.js');
const CommandGlobals = require('../../../../lib/globals/commands.js');

describe('.waitUntil()', function () {
Expand Down Expand Up @@ -285,5 +286,27 @@ describe('.waitUntil()', function () {
}
});
});

it('client.waitUntil() function returns promise for async Nightwatch commands in callback', function (done) {
MockServer.addMock({
url: '/wd/hub/session/1352110219202/title',
method: 'GET',
response: JSON.stringify({
sessionId: '1352110219202',
status: 0,
value: 'sample Title'
})
});

this.client.api.waitUntil(async function () {
const title = await this.client.api.getTitle();

return title === 'sample Title';
}, function (result) {
assert.strictEqual(result.status, 0);
});

this.client.start(done);
});
});
});