Skip to content

Commit

Permalink
[bidi][js] Deprecate argument value wrapper class (#14251)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Jul 11, 2024
1 parent 12769d6 commit 7951238
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 29 deletions.
7 changes: 6 additions & 1 deletion javascript/node/selenium-webdriver/bidi/argumentValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,19 @@

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
}

asMap() {
if (this.value instanceof LocalValue) {
return this.value.toJson()
return this.value.asMap()
} else {
// ReferenceValue
return this.value.asMap()
Expand Down
6 changes: 5 additions & 1 deletion javascript/node/selenium-webdriver/bidi/protocolValue.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions javascript/node/selenium-webdriver/lib/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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')
Expand Down
29 changes: 14 additions & 15 deletions javascript/node/selenium-webdriver/test/bidi/local_value_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions javascript/node/selenium-webdriver/test/bidi/script_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 7951238

Please sign in to comment.