Skip to content

Commit

Permalink
[JS] stop sending desiredCapabilities to local and remote end
Browse files Browse the repository at this point in the history
  • Loading branch information
harsha509 committed Sep 11, 2022
1 parent 1c90777 commit fa6deee
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 241 deletions.
17 changes: 8 additions & 9 deletions javascript/node/selenium-webdriver/lib/webdriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class IWebDriver {

/**
* @return {!Promise<!Capabilities>} A promise that will resolve with
* the this instance's capabilities.
* the instance's capabilities.
*/
getCapabilities() {}

Expand Down Expand Up @@ -455,7 +455,7 @@ class IWebDriver {
* @return {!(IThenable<T>|WebElementPromise)} A promise that will be
* resolved with the first truthy value returned by the condition
* function, or rejected if the condition times out. If the input
* input condition is an instance of a {@link WebElementCondition},
* condition is an instance of a {@link WebElementCondition},
* the returned value will be a {@link WebElementPromise}.
* @throws {TypeError} if the provided `condition` is not a valid type.
* @template T
Expand Down Expand Up @@ -586,7 +586,7 @@ class IWebDriver {
findElements(locator) {} // eslint-disable-line

/**
* Takes a screenshot of the current page. The driver makes a best effort to
* Takes a screenshot of the current page. The driver makes the best effort to
* return a screenshot of the following, in order of preference:
*
* 1. Entire page
Expand Down Expand Up @@ -715,10 +715,9 @@ class WebDriver {
static createSession(executor, capabilities, onQuit = undefined) {
let cmd = new command.Command(command.Name.NEW_SESSION)

// For OSS remote ends.
cmd.setParameter('desiredCapabilities', capabilities)
// For W3C remote ends.
cmd.setParameter('capabilities', {
firstMatch: [{}],
alwaysMatch: filterNonW3CCaps(capabilities),
})

Expand Down Expand Up @@ -1313,7 +1312,7 @@ class WebDriver {

/**
* Sets a listener for Fetch.authRequired event from CDP
* If event is triggered, it enter username and password
* If event is triggered, it enters username and password
* and allows the test to move forward
* @param {string} username
* @param {string} password
Expand Down Expand Up @@ -2060,7 +2059,7 @@ class Window {
}

/**
* Retrieves the a rect describing the current top-level window's size and
* Retrieves a rect describing the current top-level window's size and
* position.
*
* @return {!Promise<{x: number, y: number, width: number, height: number}>}
Expand Down Expand Up @@ -2540,7 +2539,7 @@ class WebElement {
}

/**
* Locates all of the descendants of this element that match the given search
* Locates all the descendants of this element that match the given search
* criteria.
*
* @param {!(by.By|Function)} locator The locator strategy to use when
Expand Down Expand Up @@ -3073,7 +3072,7 @@ class ShadowRoot {
}

/**
* Locates all of the descendants of this element that match the given search
* Locates all the descendants of this element that match the given search
* criteria.
*
* @param {!(by.By|Function)} locator The locator strategy to use when
Expand Down
238 changes: 6 additions & 232 deletions javascript/node/selenium-webdriver/test/lib/webdriver_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,9 @@ describe('WebDriver', function () {
let executor = new FakeExecutor()
.expect(CName.NEW_SESSION)
.withParameters({
desiredCapabilities: { browserName: 'firefox' },
capabilities: {
alwaysMatch: { browserName: 'firefox' },
firstMatch: [{}],
},
})
.andReturnSuccess(aSession)
Expand All @@ -207,15 +207,12 @@ describe('WebDriver', function () {
let executor = new FakeExecutor()
.expect(CName.NEW_SESSION)
.withParameters({
desiredCapabilities: {
'moz:debuggerAddress': true,
browserName: 'firefox',
},
capabilities: {
alwaysMatch: {
'moz:debuggerAddress': true,
browserName: 'firefox',
},
firstMatch: [{}],
},
})
.andReturnSuccess(aSession)
Expand All @@ -230,9 +227,9 @@ describe('WebDriver', function () {
let executor = new FakeExecutor()
.expect(CName.NEW_SESSION)
.withParameters({
desiredCapabilities: { browserName: 'firefox', foo: 'bar' },
capabilities: {
alwaysMatch: { browserName: 'firefox' },
alwaysMatch: { browserName: 'firefox'},
firstMatch: [{}],
},
})
.andReturnSuccess(aSession)
Expand All @@ -249,9 +246,9 @@ describe('WebDriver', function () {
let executor = new FakeExecutor()
.expect(CName.NEW_SESSION)
.withParameters({
desiredCapabilities: { browserName: 'firefox' },
capabilities: {
alwaysMatch: { browserName: 'firefox' },
firstMatch: [{}],
},
})
.andReturnError(new StubError())
Expand All @@ -268,9 +265,9 @@ describe('WebDriver', function () {
let executor = new FakeExecutor()
.expect(CName.NEW_SESSION)
.withParameters({
desiredCapabilities: { browserName: 'firefox' },
capabilities: {
alwaysMatch: { browserName: 'firefox' },
firstMatch: [{}],
},
})
.andReturnError(new StubError())
Expand Down Expand Up @@ -1728,227 +1725,4 @@ describe('WebDriver', function () {
})
})
})

describe('wire format', function () {
const FAKE_DRIVER = new FakeExecutor().createDriver()

describe('can serialize', function () {
function runSerializeTest(input, want) {
let executor = new FakeExecutor()
.expect(CName.NEW_SESSION)
.withParameters({
desiredCapabilities: { 'serialize-test': want },
capabilities: { alwaysMatch: {} },
})
.andReturnSuccess({ browserName: 'firefox' })
.end()
// We stuff the value to be serialized inside of a capabilities object,
// using a non-W3C key so that the value gets dropped from the W3C
// capabilities object.
return WebDriver.createSession(executor, {
'serialize-test': input,
}).getSession()
}

it('function as a string', function () {
function foo() {
return 'foo'
}
return runSerializeTest(foo, '' + foo)
})

it('object with toJSON()', function () {
return runSerializeTest(
new Date(605728511546),
'1989-03-12T17:55:11.546Z'
)
})

it('Session', function () {
return runSerializeTest(new Session('foo', {}), 'foo')
})

it('Capabilities', function () {
const prefs = new logging.Preferences()
prefs.setLevel(logging.Type.BROWSER, logging.Level.DEBUG)

const caps = Capabilities.chrome()
caps.setLoggingPrefs(prefs)

return runSerializeTest(caps, {
browserName: 'chrome',
'goog:loggingPrefs': { browser: 'DEBUG' },
})
})

it('WebElement', function () {
return runSerializeTest(
new WebElement(FAKE_DRIVER, 'fefifofum'),
WebElement.buildId('fefifofum')
)
})

it('WebElementPromise', function () {
return runSerializeTest(
new WebElementPromise(
FAKE_DRIVER,
Promise.resolve(new WebElement(FAKE_DRIVER, 'fefifofum'))
),
WebElement.buildId('fefifofum')
)
})

describe('an array', function () {
it('with Serializable', function () {
return runSerializeTest([new Session('foo', {})], ['foo'])
})

it('with WebElement', function () {
return runSerializeTest(
[new WebElement(FAKE_DRIVER, 'fefifofum')],
[WebElement.buildId('fefifofum')]
)
})

it('with WebElementPromise', function () {
return runSerializeTest(
[
new WebElementPromise(
FAKE_DRIVER,
Promise.resolve(new WebElement(FAKE_DRIVER, 'fefifofum'))
),
],
[WebElement.buildId('fefifofum')]
)
})

it('complex array', function () {
const expected = [
'abc',
123,
true,
WebElement.buildId('fefifofum'),
[123, { foo: 'bar' }],
]

const element = new WebElement(FAKE_DRIVER, 'fefifofum')
const input = ['abc', 123, true, element, [123, { foo: 'bar' }]]
return runSerializeTest(input, expected)
})

it('nested promises', function () {
return runSerializeTest(
['abc', Promise.resolve([123, Promise.resolve(true)])],
['abc', [123, true]]
)
})
})

describe('an object', function () {
it('literal', function () {
const expected = { sessionId: 'foo' }
return runSerializeTest({ sessionId: 'foo' }, expected)
})

it('with sub-objects', function () {
const expected = { sessionId: { value: 'foo' } }
return runSerializeTest({ sessionId: { value: 'foo' } }, expected)
})

it('with values that have toJSON', function () {
return runSerializeTest(
{ a: { b: new Date(605728511546) } },
{ a: { b: '1989-03-12T17:55:11.546Z' } }
)
})

it('with a Session', function () {
return runSerializeTest({ a: new Session('foo', {}) }, { a: 'foo' })
})

it('nested', function () {
const elementJson = WebElement.buildId('fefifofum')
const expected = {
script: 'return 1',
args: ['abc', 123, true, elementJson, [123, { foo: 'bar' }]],
sessionId: 'foo',
}

const element = new WebElement(FAKE_DRIVER, 'fefifofum')
const parameters = {
script: 'return 1',
args: ['abc', 123, true, element, [123, { foo: 'bar' }]],
sessionId: new Session('foo', {}),
}

return runSerializeTest(parameters, expected)
})

it('nested promises', function () {
const input = {
struct: Promise.resolve({
element: new WebElementPromise(
FAKE_DRIVER,
Promise.resolve(new WebElement(FAKE_DRIVER, 'fefifofum'))
),
}),
}

const want = {
struct: {
element: WebElement.buildId('fefifofum'),
},
}

return runSerializeTest(input, want)
})
})
})

describe('can deserialize', function () {
function runDeserializeTest(original, want) {
let executor = new FakeExecutor()
.expect(CName.GET_CURRENT_URL)
.andReturnSuccess(original)
.end()
let driver = executor.createDriver()
return driver.getCurrentUrl().then(function (got) {
assert.deepStrictEqual(got, want)
})
}

it('primitives', function () {
return Promise.all([
runDeserializeTest(1, 1),
runDeserializeTest('', ''),
runDeserializeTest(true, true),
runDeserializeTest(undefined, null),
runDeserializeTest(null, null),
])
})

it('simple object', function () {
return runDeserializeTest({ sessionId: 'foo' }, { sessionId: 'foo' })
})

it('nested object', function () {
return runDeserializeTest({ foo: { bar: 123 } }, { foo: { bar: 123 } })
})

it('array', function () {
return runDeserializeTest(
[{ foo: { bar: 123 } }],
[{ foo: { bar: 123 } }]
)
})

it('passes through function properties', function () {
function bar() {}
return runDeserializeTest(
[{ foo: { bar: 123 }, func: bar }],
[{ foo: { bar: 123 }, func: bar }]
)
})
})
})
})

5 comments on commit fa6deee

@StanislavKharchenko
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean that passing such capabilities, like "timeZone", "enableVNC" will no longer available?
We have an issue that with selenium-webdriver 4.5 and selenoid capability "timeZone" is not working.

@diemol
Copy link
Member

@diemol diemol commented on fa6deee Oct 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All non W3C WebDriver capabilities need to be prefixed. For example, in the Docker Selenium Grid, to set a time zone, you need to prefix it like this se:timeZone.

@forfan06
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we do with desiredCapabilities, like "app" after this change? I am trying to launch windows application with this. but I got bad request with the latest version, because the property "app" will be deleted in filterNonW3CCaps()....
Hope somebody get my message.

@diemol
Copy link
Member

@diemol diemol commented on fa6deee Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to prefix it, if it is app from Appium, then appium:app

@forfan06
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diemol Thanks for reply.
I am using Windows Application Driver, I also tried add prefix the property, like below
{
browserName: '',
platformName: 'Windows', // and also with "windows"
deviceName: 'WindowsPC',
'appium:app': 'Microsoft.WindowsCalculator_8wekyb3d8bbwe!App'
}
After some research, it looks like a problem on WinAppDriver side, it does not adjust with the newest appium/selenium.
Thanks anyway.

Please sign in to comment.