Skip to content

Commit

Permalink
[js] Allow builder to set a single arbitrary capability (#9857)
Browse files Browse the repository at this point in the history
  • Loading branch information
pujagani authored Sep 29, 2021
1 parent 9a767b5 commit 1c817b5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
13 changes: 13 additions & 0 deletions javascript/node/selenium-webdriver/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions javascript/node/selenium-webdriver/test/builder_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 1c817b5

Please sign in to comment.