diff --git a/javascript/node/selenium-webdriver/index.js b/javascript/node/selenium-webdriver/index.js index 317cbea441997..eb9ba36edf437 100644 --- a/javascript/node/selenium-webdriver/index.js +++ b/javascript/node/selenium-webdriver/index.js @@ -339,6 +339,19 @@ class Builder { getCapabilities() { return this.capabilities_ } + + /** + * Sets the desired capability when requesting a new session. + * If there is already a capability named key, its value will be overwritten with value. + * This is a convenience wrapper around builder.getCapabilities().set(key, value) to support Builder method chaining. + * @param {string} key The capability key. + * @param {*} value The capability value. + * @return {!Builder} A self reference. + */ + setCapability(key, value) { + this.capabilities_.set(key, value) + return this + } /** * Configures the target browser for clients created by this instance. diff --git a/javascript/node/selenium-webdriver/test/builder_test.js b/javascript/node/selenium-webdriver/test/builder_test.js index 911c2f7c53984..ead53a34f670f 100644 --- a/javascript/node/selenium-webdriver/test/builder_test.js +++ b/javascript/node/selenium-webdriver/test/builder_test.js @@ -27,6 +27,7 @@ const safari = require('../safari') const test = require('../lib/test') const { Browser } = require('../lib/capabilities') const { Pages } = require('../lib/test') +const { Builder } = require('../../selenium-webdriver/index') test.suite(function (env) { const BROWSER_MAP = new Map([ @@ -68,6 +69,29 @@ test.suite(function (env) { }) }) } + + if (BROWSER_MAP.has(env.browser.name)) { + describe('builder allows to set a single capability', function () { + let driver + + after(() => driver && driver.quit()) + + it(env.browser.name, async function () { + let timeouts = { implicit: 0, pageLoad: 1000, script: 1000 } + driver = new Builder() + .setCapability('timeouts', timeouts) + .forBrowser(env.browser.name) + .build() + + let caps = await getCaps(driver); + assert.deepEqual(caps.get('timeouts'), timeouts) + }) + }) + } + + async function getCaps(driver) { + return driver.getCapabilities(); + } }) describe('Builder', function () {