Skip to content

Commit 1c817b5

Browse files
authored
[js] Allow builder to set a single arbitrary capability (#9857)
1 parent 9a767b5 commit 1c817b5

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

javascript/node/selenium-webdriver/index.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,19 @@ class Builder {
339339
getCapabilities() {
340340
return this.capabilities_
341341
}
342+
343+
/**
344+
* Sets the desired capability when requesting a new session.
345+
* If there is already a capability named key, its value will be overwritten with value.
346+
* This is a convenience wrapper around builder.getCapabilities().set(key, value) to support Builder method chaining.
347+
* @param {string} key The capability key.
348+
* @param {*} value The capability value.
349+
* @return {!Builder} A self reference.
350+
*/
351+
setCapability(key, value) {
352+
this.capabilities_.set(key, value)
353+
return this
354+
}
342355

343356
/**
344357
* Configures the target browser for clients created by this instance.

javascript/node/selenium-webdriver/test/builder_test.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const safari = require('../safari')
2727
const test = require('../lib/test')
2828
const { Browser } = require('../lib/capabilities')
2929
const { Pages } = require('../lib/test')
30+
const { Builder } = require('../../selenium-webdriver/index')
3031

3132
test.suite(function (env) {
3233
const BROWSER_MAP = new Map([
@@ -68,6 +69,29 @@ test.suite(function (env) {
6869
})
6970
})
7071
}
72+
73+
if (BROWSER_MAP.has(env.browser.name)) {
74+
describe('builder allows to set a single capability', function () {
75+
let driver
76+
77+
after(() => driver && driver.quit())
78+
79+
it(env.browser.name, async function () {
80+
let timeouts = { implicit: 0, pageLoad: 1000, script: 1000 }
81+
driver = new Builder()
82+
.setCapability('timeouts', timeouts)
83+
.forBrowser(env.browser.name)
84+
.build()
85+
86+
let caps = await getCaps(driver);
87+
assert.deepEqual(caps.get('timeouts'), timeouts)
88+
})
89+
})
90+
}
91+
92+
async function getCaps(driver) {
93+
return driver.getCapabilities();
94+
}
7195
})
7296

7397
describe('Builder', function () {

0 commit comments

Comments
 (0)