From 79512380c6abd194b616b6161907f861ff452c7e Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Thu, 11 Jul 2024 17:24:12 +0530 Subject: [PATCH] [bidi][js] Deprecate argument value wrapper class (#14251) --- .../selenium-webdriver/bidi/argumentValue.js | 7 ++++- .../selenium-webdriver/bidi/protocolValue.js | 6 +++- .../node/selenium-webdriver/lib/script.js | 3 +- .../test/bidi/local_value_test.js | 29 +++++++++---------- .../test/bidi/locate_nodes_test.js | 3 +- .../test/bidi/script_test.js | 16 +++++----- 6 files changed, 35 insertions(+), 29 deletions(-) diff --git a/javascript/node/selenium-webdriver/bidi/argumentValue.js b/javascript/node/selenium-webdriver/bidi/argumentValue.js index 57ee705652671..c1598b86d631d 100644 --- a/javascript/node/selenium-webdriver/bidi/argumentValue.js +++ b/javascript/node/selenium-webdriver/bidi/argumentValue.js @@ -17,6 +17,11 @@ const { LocalValue } = require('./protocolValue') +/** + * @deprecated + * in favor of LocalValue methods for all argument values. + * This extra wrapper is not required. + */ class ArgumentValue { constructor(value) { this.value = value @@ -24,7 +29,7 @@ class ArgumentValue { asMap() { if (this.value instanceof LocalValue) { - return this.value.toJson() + return this.value.asMap() } else { // ReferenceValue return this.value.asMap() diff --git a/javascript/node/selenium-webdriver/bidi/protocolValue.js b/javascript/node/selenium-webdriver/bidi/protocolValue.js index 1d6f88e822518..059621b792e9e 100644 --- a/javascript/node/selenium-webdriver/bidi/protocolValue.js +++ b/javascript/node/selenium-webdriver/bidi/protocolValue.js @@ -185,7 +185,11 @@ class LocalValue { return new LocalValue(NonPrimitiveType.CHANNEL, value) } - toJson() { + static createReferenceValue(handle, sharedId) { + return new ReferenceValue(handle, sharedId) + } + + asMap() { let toReturn = {} toReturn[TYPE_CONSTANT] = this.type diff --git a/javascript/node/selenium-webdriver/lib/script.js b/javascript/node/selenium-webdriver/lib/script.js index cd1aed675e979..2a64dd03e7d56 100644 --- a/javascript/node/selenium-webdriver/lib/script.js +++ b/javascript/node/selenium-webdriver/lib/script.js @@ -17,7 +17,6 @@ const logInspector = require('../bidi/logInspector') const scriptManager = require('../bidi//scriptManager') -const { ArgumentValue } = require('../bidi/argumentValue') const { LocalValue, ChannelValue } = require('../bidi/protocolValue') const fs = require('node:fs') const path = require('node:path') @@ -77,7 +76,7 @@ class Script { await this.#initScript() let argumentValues = [] - let value = new ArgumentValue(LocalValue.createChannelValue(new ChannelValue('channel_name'))) + let value = LocalValue.createChannelValue(new ChannelValue('channel_name')) argumentValues.push(value) const filePath = path.join(__dirname, 'atoms', 'bidi-mutation-listener.js') diff --git a/javascript/node/selenium-webdriver/test/bidi/local_value_test.js b/javascript/node/selenium-webdriver/test/bidi/local_value_test.js index 61f9645b5e303..d7bc7c4eeef5c 100644 --- a/javascript/node/selenium-webdriver/test/bidi/local_value_test.js +++ b/javascript/node/selenium-webdriver/test/bidi/local_value_test.js @@ -23,7 +23,6 @@ const { suite } = require('../../lib/test') const ScriptManager = require('selenium-webdriver/bidi/scriptManager') const { LocalValue, RegExpValue } = require('selenium-webdriver/bidi/protocolValue') -const { ArgumentValue } = require('selenium-webdriver/bidi/argumentValue') const { EvaluateResultType } = require('selenium-webdriver/bidi/evaluateResult') const { SpecialNumberType } = require('selenium-webdriver/bidi/protocolType') @@ -44,7 +43,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createUndefinedValue()) + let value = LocalValue.createUndefinedValue() argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -67,7 +66,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createNullValue()) + let value = LocalValue.createNullValue() argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -90,7 +89,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createSpecialNumberValue(SpecialNumberType.MINUS_ZERO)) + let value = LocalValue.createSpecialNumberValue(SpecialNumberType.MINUS_ZERO) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -115,7 +114,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createSpecialNumberValue(SpecialNumberType.INFINITY)) + let value = LocalValue.createSpecialNumberValue(SpecialNumberType.INFINITY) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -140,7 +139,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createSpecialNumberValue(SpecialNumberType.MINUS_INFINITY)) + let value = LocalValue.createSpecialNumberValue(SpecialNumberType.MINUS_INFINITY) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -165,7 +164,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createNumberValue(1.4)) + let value = LocalValue.createNumberValue(1.4) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -190,7 +189,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createBooleanValue(true)) + let value = LocalValue.createBooleanValue(true) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -215,7 +214,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createBigIntValue('42')) + let value = LocalValue.createBigIntValue('42') argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -241,7 +240,7 @@ suite( const manager = await ScriptManager(id, driver) let argumentValues = [] let arrayValue = [LocalValue.createStringValue('foobar')] - let value = new ArgumentValue(LocalValue.createArrayValue(arrayValue)) + let value = LocalValue.createArrayValue(arrayValue) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -272,7 +271,7 @@ suite( const manager = await ScriptManager(id, driver) let argumentValues = [] let setValue = [LocalValue.createStringValue('foobar')] - let value = new ArgumentValue(LocalValue.createSetValue(setValue)) + let value = LocalValue.createSetValue(setValue) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -302,7 +301,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createDateValue('2022-05-31T13:47:29.000Z')) + let value = LocalValue.createDateValue('2022-05-31T13:47:29.000Z') argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -329,7 +328,7 @@ suite( const manager = await ScriptManager(id, driver) let argumentValues = [] let mapValue = { foobar: LocalValue.createStringValue('foobar') } - let value = new ArgumentValue(LocalValue.createMapValue(mapValue)) + let value = LocalValue.createMapValue(mapValue) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -361,7 +360,7 @@ suite( const manager = await ScriptManager(id, driver) let argumentValues = [] let mapValue = { foobar: LocalValue.createStringValue('foobar') } - let value = new ArgumentValue(LocalValue.createObjectValue(mapValue)) + let value = LocalValue.createObjectValue(mapValue) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( @@ -391,7 +390,7 @@ suite( const id = await driver.getWindowHandle() const manager = await ScriptManager(id, driver) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createRegularExpressionValue(new RegExpValue('foo', 'g'))) + let value = LocalValue.createRegularExpressionValue(new RegExpValue('foo', 'g')) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext( diff --git a/javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js b/javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js index ff8e9b7c6c4b6..a2736b5f40fab 100644 --- a/javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js +++ b/javascript/node/selenium-webdriver/test/bidi/locate_nodes_test.js @@ -25,7 +25,6 @@ const { Locator } = require('selenium-webdriver/bidi/browsingContext') const { ScriptManager } = require('selenium-webdriver/index') const { EvaluateResultType } = require('selenium-webdriver/bidi/evaluateResult') const { LocalValue, ReferenceValue } = require('selenium-webdriver/bidi/protocolValue') -const { ArgumentValue } = require('selenium-webdriver/bidi/argumentValue') suite( function (env) { @@ -187,7 +186,7 @@ suite( let argumentValues = [] let mapValue = { sharedId: LocalValue.createStringValue(nodeId) } - argumentValues.push(new ArgumentValue(LocalValue.createMapValue(mapValue))) + argumentValues.push(LocalValue.createMapValue(mapValue)) const response = await script.callFunctionInBrowsingContext( id, diff --git a/javascript/node/selenium-webdriver/test/bidi/script_test.js b/javascript/node/selenium-webdriver/test/bidi/script_test.js index f038b78377053..d47f186052f48 100644 --- a/javascript/node/selenium-webdriver/test/bidi/script_test.js +++ b/javascript/node/selenium-webdriver/test/bidi/script_test.js @@ -100,8 +100,8 @@ suite( manager = await ScriptManager(id, driver) let argumentValues = [] - let value1 = new ArgumentValue(LocalValue.createStringValue('ARGUMENT_STRING_VALUE')) - let value2 = new ArgumentValue(LocalValue.createNumberValue(42)) + let value1 = LocalValue.createStringValue('ARGUMENT_STRING_VALUE') + let value2 = LocalValue.createNumberValue(42) argumentValues.push(value1) argumentValues.push(value2) @@ -160,7 +160,7 @@ suite( manager = await ScriptManager(id, driver) let mapValue = { some_property: LocalValue.createNumberValue(42) } - let thisParameter = new ArgumentValue(LocalValue.createObjectValue(mapValue)).asMap() + let thisParameter = LocalValue.createObjectValue(mapValue).asMap() const result = await manager.callFunctionInBrowsingContext( id, @@ -427,8 +427,8 @@ suite( let argumentValues = [] let valueMap = evaluateResult.result.value - let value1 = new ArgumentValue(LocalValue.createObjectValue(valueMap)) - let value2 = new ArgumentValue(new ReferenceValue(RemoteReferenceType.HANDLE, evaluateResult.result.handle)) + let value1 = LocalValue.createObjectValue(valueMap) + let value2 = new ReferenceValue(RemoteReferenceType.HANDLE, evaluateResult.result.handle) argumentValues.push(value1) argumentValues.push(value2) @@ -462,8 +462,8 @@ suite( let argumentValues = [] let valueMap = evaluateResult.result.value - let value1 = new ArgumentValue(LocalValue.createObjectValue(valueMap)) - let value2 = new ArgumentValue(new ReferenceValue(RemoteReferenceType.HANDLE, evaluateResult.result.handle)) + let value1 = LocalValue.createObjectValue(valueMap) + let value2 = new ReferenceValue(RemoteReferenceType.HANDLE, evaluateResult.result.handle) argumentValues.push(value1) argumentValues.push(value2) @@ -766,7 +766,7 @@ suite( }) let argumentValues = [] - let value = new ArgumentValue(LocalValue.createChannelValue(new ChannelValue('channel_name'))) + let value = LocalValue.createChannelValue(new ChannelValue('channel_name')) argumentValues.push(value) const result = await manager.callFunctionInBrowsingContext(