From 197377c5a37cbb17f246f23e91f529e534f8c843 Mon Sep 17 00:00:00 2001 From: capGoblin Date: Sun, 7 Apr 2024 00:16:13 +0530 Subject: [PATCH 1/2] add alwaysAsync to waitUntil --- lib/api/protocol/waitUntil.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/api/protocol/waitUntil.js b/lib/api/protocol/waitUntil.js index feb693a3f..c60a36151 100644 --- a/lib/api/protocol/waitUntil.js +++ b/lib/api/protocol/waitUntil.js @@ -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}; From 73c5e2b692fa02fa075b1cc659cc00b1766d8887 Mon Sep 17 00:00:00 2001 From: capGoblin Date: Sun, 21 Apr 2024 20:13:12 +0530 Subject: [PATCH 2/2] add test for waitUntil() --- test/src/api/commands/client/testWaitUntil.js | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/src/api/commands/client/testWaitUntil.js b/test/src/api/commands/client/testWaitUntil.js index f0873298a..dbd3b84df 100644 --- a/test/src/api/commands/client/testWaitUntil.js +++ b/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 () { @@ -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); + }); }); });