From 1db3b3477cbae191c23466fca6820a2bf69869b1 Mon Sep 17 00:00:00 2001 From: yashPratp983 Date: Mon, 10 Jul 2023 01:36:06 +0530 Subject: [PATCH 1/7] move network commands to network namespace --- .../{ => network}/captureNetworkRequests.js | 8 ++++++-- .../client-commands/{ => network}/mockNetworkResponse.js | 8 ++++++-- .../{ => network}/setNetworkConditions.js | 9 +++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) rename lib/api/client-commands/{ => network}/captureNetworkRequests.js (90%) rename lib/api/client-commands/{ => network}/mockNetworkResponse.js (91%) rename lib/api/client-commands/{ => network}/setNetworkConditions.js (85%) diff --git a/lib/api/client-commands/captureNetworkRequests.js b/lib/api/client-commands/network/captureNetworkRequests.js similarity index 90% rename from lib/api/client-commands/captureNetworkRequests.js rename to lib/api/client-commands/network/captureNetworkRequests.js index d71794cdb2..113aa42b12 100644 --- a/lib/api/client-commands/captureNetworkRequests.js +++ b/lib/api/client-commands/network/captureNetworkRequests.js @@ -1,5 +1,5 @@ -const ClientCommand = require('./_base-command.js'); -const {Logger} = require('../../utils'); +const ClientCommand = require('../_base-command.js'); +const {Logger} = require('../../../utils/index.js'); /** * Capture outgoing network calls from the browser. @@ -28,6 +28,10 @@ const {Logger} = require('../../utils'); */ class CaptureNetworkCalls extends ClientCommand { + static get namespacedAliases() { + return 'captureNetworkRequests'; + } + performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { diff --git a/lib/api/client-commands/mockNetworkResponse.js b/lib/api/client-commands/network/mockNetworkResponse.js similarity index 91% rename from lib/api/client-commands/mockNetworkResponse.js rename to lib/api/client-commands/network/mockNetworkResponse.js index e564b46a7e..5ad8e5ba57 100644 --- a/lib/api/client-commands/mockNetworkResponse.js +++ b/lib/api/client-commands/network/mockNetworkResponse.js @@ -1,5 +1,5 @@ -const ClientCommand = require('./_base-command.js'); -const {Logger} = require('../../utils'); +const ClientCommand = require('../_base-command.js'); +const {Logger} = require('../../../utils/index.js'); /** * Intercept the request made on a particular URL and mock the response. @@ -31,6 +31,10 @@ const {Logger} = require('../../utils'); */ class MockNetworkResponse extends ClientCommand { + static get namespacedAliases() { + return 'mockNetworkResponse'; + } + performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { diff --git a/lib/api/client-commands/setNetworkConditions.js b/lib/api/client-commands/network/setNetworkConditions.js similarity index 85% rename from lib/api/client-commands/setNetworkConditions.js rename to lib/api/client-commands/network/setNetworkConditions.js index 6a932c70c7..a421ba0abb 100644 --- a/lib/api/client-commands/setNetworkConditions.js +++ b/lib/api/client-commands/network/setNetworkConditions.js @@ -1,5 +1,5 @@ -const ClientCommand = require('./_base-command.js'); -const {Logger} = require('../../utils'); +const ClientCommand = require('../_base-command.js'); +const {Logger} = require('../../../utils/index.js'); /** * @@ -23,6 +23,11 @@ const {Logger} = require('../../utils'); * @api protocol.sessions */ class SetNetworkConditions extends ClientCommand { + + static get namespacedAliases() { + return 'setNetworkConditions'; + } + performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { const error = new Error('SetNetworkConditions is not supported while using this driver'); From 3b6d3beb326ad5ca41d34165298e3949358b2e22 Mon Sep 17 00:00:00 2001 From: yashPratp983 Date: Fri, 14 Jul 2023 20:46:27 +0530 Subject: [PATCH 2/7] Revert "move network commands to network namespace" This reverts commit 1db3b3477cbae191c23466fca6820a2bf69869b1. --- .../{network => }/captureNetworkRequests.js | 8 ++------ .../client-commands/{network => }/mockNetworkResponse.js | 8 ++------ .../{network => }/setNetworkConditions.js | 9 ++------- 3 files changed, 6 insertions(+), 19 deletions(-) rename lib/api/client-commands/{network => }/captureNetworkRequests.js (90%) rename lib/api/client-commands/{network => }/mockNetworkResponse.js (91%) rename lib/api/client-commands/{network => }/setNetworkConditions.js (85%) diff --git a/lib/api/client-commands/network/captureNetworkRequests.js b/lib/api/client-commands/captureNetworkRequests.js similarity index 90% rename from lib/api/client-commands/network/captureNetworkRequests.js rename to lib/api/client-commands/captureNetworkRequests.js index 113aa42b12..d71794cdb2 100644 --- a/lib/api/client-commands/network/captureNetworkRequests.js +++ b/lib/api/client-commands/captureNetworkRequests.js @@ -1,5 +1,5 @@ -const ClientCommand = require('../_base-command.js'); -const {Logger} = require('../../../utils/index.js'); +const ClientCommand = require('./_base-command.js'); +const {Logger} = require('../../utils'); /** * Capture outgoing network calls from the browser. @@ -28,10 +28,6 @@ const {Logger} = require('../../../utils/index.js'); */ class CaptureNetworkCalls extends ClientCommand { - static get namespacedAliases() { - return 'captureNetworkRequests'; - } - performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { diff --git a/lib/api/client-commands/network/mockNetworkResponse.js b/lib/api/client-commands/mockNetworkResponse.js similarity index 91% rename from lib/api/client-commands/network/mockNetworkResponse.js rename to lib/api/client-commands/mockNetworkResponse.js index 5ad8e5ba57..e564b46a7e 100644 --- a/lib/api/client-commands/network/mockNetworkResponse.js +++ b/lib/api/client-commands/mockNetworkResponse.js @@ -1,5 +1,5 @@ -const ClientCommand = require('../_base-command.js'); -const {Logger} = require('../../../utils/index.js'); +const ClientCommand = require('./_base-command.js'); +const {Logger} = require('../../utils'); /** * Intercept the request made on a particular URL and mock the response. @@ -31,10 +31,6 @@ const {Logger} = require('../../../utils/index.js'); */ class MockNetworkResponse extends ClientCommand { - static get namespacedAliases() { - return 'mockNetworkResponse'; - } - performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { diff --git a/lib/api/client-commands/network/setNetworkConditions.js b/lib/api/client-commands/setNetworkConditions.js similarity index 85% rename from lib/api/client-commands/network/setNetworkConditions.js rename to lib/api/client-commands/setNetworkConditions.js index a421ba0abb..6a932c70c7 100644 --- a/lib/api/client-commands/network/setNetworkConditions.js +++ b/lib/api/client-commands/setNetworkConditions.js @@ -1,5 +1,5 @@ -const ClientCommand = require('../_base-command.js'); -const {Logger} = require('../../../utils/index.js'); +const ClientCommand = require('./_base-command.js'); +const {Logger} = require('../../utils'); /** * @@ -23,11 +23,6 @@ const {Logger} = require('../../../utils/index.js'); * @api protocol.sessions */ class SetNetworkConditions extends ClientCommand { - - static get namespacedAliases() { - return 'setNetworkConditions'; - } - performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { const error = new Error('SetNetworkConditions is not supported while using this driver'); From 59b9f21b09c628f47e1d5fc2fd3ae878c9c90e8d Mon Sep 17 00:00:00 2001 From: yashPratp983 Date: Fri, 14 Jul 2023 21:03:38 +0530 Subject: [PATCH 3/7] changed error message for using non-chromium driver for setNetworkConditions and registerBasicAuth --- lib/api/client-commands/registerBasicAuth.js | 2 +- lib/api/client-commands/setNetworkConditions.js | 2 +- test/src/api/commands/client/testRegisterBasicAuth.js | 2 +- test/src/api/commands/client/testSetNetworkConditions.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/api/client-commands/registerBasicAuth.js b/lib/api/client-commands/registerBasicAuth.js index 1b15fadb54..e6e5032d35 100644 --- a/lib/api/client-commands/registerBasicAuth.js +++ b/lib/api/client-commands/registerBasicAuth.js @@ -28,7 +28,7 @@ class RegisterBasicAuth extends ClientCommand { performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { - const error = new Error('RegisterBasicAuth is not supported while using this driver'); + const error = new Error('The command .registerBasicAuth() is only supported in Chrome and Edge drivers'); Logger.error(error); return callback(error); diff --git a/lib/api/client-commands/setNetworkConditions.js b/lib/api/client-commands/setNetworkConditions.js index 6a932c70c7..b64e623e7d 100644 --- a/lib/api/client-commands/setNetworkConditions.js +++ b/lib/api/client-commands/setNetworkConditions.js @@ -25,7 +25,7 @@ const {Logger} = require('../../utils'); class SetNetworkConditions extends ClientCommand { performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { - const error = new Error('SetNetworkConditions is not supported while using this driver'); + const error = new Error('The command .setNetworkConditions() is only supported in Chrome and Edge drivers'); Logger.error(error); return callback(error); diff --git a/test/src/api/commands/client/testRegisterBasicAuth.js b/test/src/api/commands/client/testRegisterBasicAuth.js index 7f4c758e7a..5bb2ca731e 100644 --- a/test/src/api/commands/client/testRegisterBasicAuth.js +++ b/test/src/api/commands/client/testRegisterBasicAuth.js @@ -65,7 +65,7 @@ describe('.registerBasicAuth()', function () { }).then(client => { client.api.registerBasicAuth('admin', 'admin', function(result){ assert.strictEqual(result.status, -1); - assert.strictEqual(result.error, 'RegisterBasicAuth is not supported while using this driver'); + assert.strictEqual(result.error, 'The command .registerBasicAuth() is only supported in Chrome and Edge drivers'); }); client.start(done); diff --git a/test/src/api/commands/client/testSetNetworkConditions.js b/test/src/api/commands/client/testSetNetworkConditions.js index 9087db3531..05f8ac618f 100644 --- a/test/src/api/commands/client/testSetNetworkConditions.js +++ b/test/src/api/commands/client/testSetNetworkConditions.js @@ -73,7 +73,7 @@ describe('.setNetworkConditions()', function () { }, function (result) { assert.strictEqual(result.status, -1); - assert.strictEqual(result.error, 'SetNetworkConditions is not supported while using this driver'); + assert.strictEqual(result.error, 'The command .setNetworkConditions() is only supported in Chrome and Edge drivers'); } ); client.start(done); From d0e844f189ebf99e487b57bb9587a67835f73ded Mon Sep 17 00:00:00 2001 From: yashPratp983 Date: Tue, 18 Jul 2023 16:47:13 +0530 Subject: [PATCH 4/7] Changed error message to use chromium based driver --- lib/api/client-commands/registerBasicAuth.js | 2 +- lib/api/client-commands/setNetworkConditions.js | 2 +- test/src/api/commands/client/testRegisterBasicAuth.js | 2 +- test/src/api/commands/client/testSetNetworkConditions.js | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/api/client-commands/registerBasicAuth.js b/lib/api/client-commands/registerBasicAuth.js index e6e5032d35..715a123534 100644 --- a/lib/api/client-commands/registerBasicAuth.js +++ b/lib/api/client-commands/registerBasicAuth.js @@ -28,7 +28,7 @@ class RegisterBasicAuth extends ClientCommand { performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { - const error = new Error('The command .registerBasicAuth() is only supported in Chrome and Edge drivers'); + const error = new Error('The command .registerBasicAuth() is only supported in Chromium based drivers'); Logger.error(error); return callback(error); diff --git a/lib/api/client-commands/setNetworkConditions.js b/lib/api/client-commands/setNetworkConditions.js index b64e623e7d..d0b38c3679 100644 --- a/lib/api/client-commands/setNetworkConditions.js +++ b/lib/api/client-commands/setNetworkConditions.js @@ -25,7 +25,7 @@ const {Logger} = require('../../utils'); class SetNetworkConditions extends ClientCommand { performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { - const error = new Error('The command .setNetworkConditions() is only supported in Chrome and Edge drivers'); + const error = new Error('The command .setNetworkConditions() is only supported in Chromium based drivers'); Logger.error(error); return callback(error); diff --git a/test/src/api/commands/client/testRegisterBasicAuth.js b/test/src/api/commands/client/testRegisterBasicAuth.js index 5bb2ca731e..d5ed4e253f 100644 --- a/test/src/api/commands/client/testRegisterBasicAuth.js +++ b/test/src/api/commands/client/testRegisterBasicAuth.js @@ -65,7 +65,7 @@ describe('.registerBasicAuth()', function () { }).then(client => { client.api.registerBasicAuth('admin', 'admin', function(result){ assert.strictEqual(result.status, -1); - assert.strictEqual(result.error, 'The command .registerBasicAuth() is only supported in Chrome and Edge drivers'); + assert.strictEqual(result.error, 'The command .registerBasicAuth() is only supported in Chromium based drivers'); }); client.start(done); diff --git a/test/src/api/commands/client/testSetNetworkConditions.js b/test/src/api/commands/client/testSetNetworkConditions.js index 05f8ac618f..8ebc52da2a 100644 --- a/test/src/api/commands/client/testSetNetworkConditions.js +++ b/test/src/api/commands/client/testSetNetworkConditions.js @@ -73,7 +73,7 @@ describe('.setNetworkConditions()', function () { }, function (result) { assert.strictEqual(result.status, -1); - assert.strictEqual(result.error, 'The command .setNetworkConditions() is only supported in Chrome and Edge drivers'); + assert.strictEqual(result.error, 'The command .setNetworkConditions() is only supported in Chromium based drivers'); } ); client.start(done); From 697b26ba92fffe960947ddb9413f3e0236f75f80 Mon Sep 17 00:00:00 2001 From: yashPratp983 Date: Wed, 19 Jul 2023 18:02:12 +0530 Subject: [PATCH 5/7] deleted lib/api/client-commands/setNetworkConditions.js to solve merge conflict --- .../client-commands/setNetworkConditions.js | 46 ------------------- 1 file changed, 46 deletions(-) delete mode 100644 lib/api/client-commands/setNetworkConditions.js diff --git a/lib/api/client-commands/setNetworkConditions.js b/lib/api/client-commands/setNetworkConditions.js deleted file mode 100644 index d0b38c3679..0000000000 --- a/lib/api/client-commands/setNetworkConditions.js +++ /dev/null @@ -1,46 +0,0 @@ -const ClientCommand = require('./_base-command.js'); -const {Logger} = require('../../utils'); - -/** - * - * Command to set Chrome network emulation settings. - * - * @example - * this.demoTest = function (browser) { - * browser.setNetworkConditions({ - * offline: false, - * latency: 50000, - * download_throughput: 450 * 1024, - * upload_throughput: 150 * 1024 - * }); - * }; - * - * - * @method setNetworkConditions - * @syntax .setNetworkConditions(spec, [callback]) - * @param {object} spec - * @param {function} [callback] Optional callback function to be called when the command finishes. - * @api protocol.sessions - */ -class SetNetworkConditions extends ClientCommand { - performAction(callback) { - if (!this.api.isChrome() && !this.api.isEdge()) { - const error = new Error('The command .setNetworkConditions() is only supported in Chromium based drivers'); - Logger.error(error); - - return callback(error); - } - - const {spec} = this; - - this.transportActions.setNetworkConditions(spec, callback); - } - - command(spec, callback) { - this.spec = spec; - - return super.command(callback); - } -} - -module.exports = SetNetworkConditions; From 7f7c04cbf32321e66de0b79b130fcf043354f131 Mon Sep 17 00:00:00 2001 From: yashPratp983 Date: Wed, 19 Jul 2023 18:15:20 +0530 Subject: [PATCH 6/7] modified error message regarding browser-compatibility in lib/api/client-commands/setConditions.js file --- lib/api/client-commands/network/setConditions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/client-commands/network/setConditions.js b/lib/api/client-commands/network/setConditions.js index 7d642f4b6e..c246705877 100644 --- a/lib/api/client-commands/network/setConditions.js +++ b/lib/api/client-commands/network/setConditions.js @@ -33,7 +33,7 @@ class SetNetworkConditions extends ClientCommand { performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { - const error = new Error('SetNetworkConditions is not supported while using this driver'); + const error = new Error('The command setNetworkConditions() is only supported in Chromium based drivers'); Logger.error(error); return callback(error); From 034de47af1b99af3d0ae1bd933aabca5ea625d66 Mon Sep 17 00:00:00 2001 From: yashPratp983 Date: Wed, 19 Jul 2023 18:32:50 +0530 Subject: [PATCH 7/7] added . before setNetworkConditions in error message in lib/api/client-commands/setConditions.js --- lib/api/client-commands/network/setConditions.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/api/client-commands/network/setConditions.js b/lib/api/client-commands/network/setConditions.js index c246705877..a3f8f34b70 100644 --- a/lib/api/client-commands/network/setConditions.js +++ b/lib/api/client-commands/network/setConditions.js @@ -33,7 +33,7 @@ class SetNetworkConditions extends ClientCommand { performAction(callback) { if (!this.api.isChrome() && !this.api.isEdge()) { - const error = new Error('The command setNetworkConditions() is only supported in Chromium based drivers'); + const error = new Error('The command .setNetworkConditions() is only supported in Chromium based drivers'); Logger.error(error); return callback(error);