Skip to content

Commit 23f6bdc

Browse files
bolasblackcorevo
authored andcommitted
selenium-side-runner support multiple nested capabilities
For example: ```bash selenium-side-runner -c " browserName='chrome' screener.name='My Chrome Test' screener.resolution='1280x1024' screener.apiKey='xxx' screener.group='xxx' " ```
1 parent 4a79aa5 commit 23f6bdc

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

packages/selenium-side-runner/src/__test__/capabilities.spec.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,20 @@ describe('capabilities string parser', () => {
7474
},
7575
})
7676
})
77+
it('should parse multiple dot-notation capability key', () => {
78+
const capabilities = `
79+
webdriver.remote.sessionid=someId
80+
webdriver.remote.username=username
81+
`
82+
expect(Capabilities.parseString(capabilities)).toEqual({
83+
webdriver: {
84+
remote: {
85+
sessionid: 'someId',
86+
username: 'username',
87+
},
88+
},
89+
})
90+
})
7791
it('should parse dot-notation arrays', () => {
7892
const capabilities = 'chromeOptions.args=[disable-infobars, headless]'
7993
expect(Capabilities.parseString(capabilities)).toEqual({

packages/selenium-side-runner/src/capabilities.js

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function parseString(input) {
1919
const capabilities = {}
2020

2121
matchStringPairs(input).forEach(({ key, value }) => {
22-
Object.assign(capabilities, assignStringKey(key, parseStringValue(value)))
22+
assignStringKey(key, parseStringValue(value), capabilities)
2323
})
2424

2525
return capabilities
@@ -30,7 +30,7 @@ export default {
3030
}
3131

3232
function matchStringPairs(input) {
33-
const regex = /([^ =]*) ?= ?(".*"|'.*'|\[.*\]|[^ ]*)/g
33+
const regex = /([^\s=]*)\s?=\s?(".*"|'.*'|\[.*\]|[^\s]*)/g
3434
let result
3535
const splitCapabilities = []
3636
while ((result = regex.exec(input)) !== null) {
@@ -40,10 +40,14 @@ function matchStringPairs(input) {
4040
return splitCapabilities
4141
}
4242

43-
function assignStringKey(key, value) {
44-
const keyObject = {}
43+
function assignStringKey(key, value, keyObject) {
44+
keyObject = keyObject || {}
45+
4546
key.split('.').reduce((objectKey, currKey, index, keys) => {
46-
const ref = {}
47+
const ref =
48+
!objectKey[currKey] || typeof objectKey[currKey] !== 'object'
49+
? {}
50+
: objectKey[currKey]
4751
objectKey[currKey] = keys.length === index + 1 ? value : ref
4852
return ref
4953
}, keyObject)

0 commit comments

Comments
 (0)