Skip to content

Commit 8edc13b

Browse files
committed
[js] Remove support for requiredCapabilities from WebDriver.createSession
1 parent 5bd212e commit 8edc13b

File tree

3 files changed

+27
-76
lines changed

3 files changed

+27
-76
lines changed

javascript/node/selenium-webdriver/CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ mode.
106106
- Removed
107107
- ElementNotVisibleError
108108
- InvalidElementCoordinatesError
109+
* Changes to `lib/webdriver.WebDriver`:
110+
- Dropped support for "requiredCapabilities" from WebDriver.createSession
109111
* Changes to `lib/webdriver.Options` (`driver.manage()`):
110112
- Removed timeouts (use get/setTimeouts)
111113
* Changes to `lib/webdriver.Window` (`driver.manage().window()`):

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,23 @@ class IWebDriver {
589589
}
590590

591591

592+
/**
593+
* @param {!Capabilities} capabilities A capabilities object.
594+
* @return {!Capabilities} A copy of the parameter capabilities, omitting
595+
* capability names that are not valid W3C names.
596+
*/
597+
function filterNonW3CCaps(capabilities) {
598+
let newCaps = new Capabilities(capabilities);
599+
for (let k of newCaps.keys()) {
600+
// Any key containing a colon is a vendor-prefixed capability.
601+
if (!(W3C_CAPABILITY_NAMES.has(k) || k.indexOf(':') >= 0)) {
602+
newCaps.delete(k);
603+
}
604+
}
605+
return newCaps;
606+
}
607+
608+
592609
/**
593610
* Each WebDriver instance provides automated control over a browser session.
594611
*
@@ -625,23 +642,6 @@ class WebDriver {
625642
/**
626643
* Creates a new WebDriver session.
627644
*
628-
* By default, the requested session `capabilities` are merely "desired" and
629-
* the remote end will still create a new session even if it cannot satisfy
630-
* all of the requested capabilities. You can query which capabilities a
631-
* session actually has using the
632-
* {@linkplain #getCapabilities() getCapabilities()} method on the returned
633-
* WebDriver instance.
634-
*
635-
* To define _required capabilities_, provide the `capabilities` as an object
636-
* literal with `required` and `desired` keys. The `desired` key may be
637-
* omitted if all capabilities are required, and vice versa. If the server
638-
* cannot create a session with all of the required capabilities, it will
639-
* return an {@linkplain error.SessionNotCreatedError}.
640-
*
641-
* let required = new Capabilities().set('browserName', 'firefox');
642-
* let desired = new Capabilities().set('version', '45');
643-
* let driver = WebDriver.createSession(executor, {required, desired});
644-
*
645645
* This function will always return a WebDriver instance. If there is an error
646646
* creating the session, such as the aforementioned SessionNotCreatedError,
647647
* the driver will have a rejected {@linkplain #getSession session} promise.
@@ -657,10 +657,8 @@ class WebDriver {
657657
*
658658
* @param {!command.Executor} executor The executor to create the new session
659659
* with.
660-
* @param {(!Capabilities|
661-
* {desired: (Capabilities|undefined),
662-
* required: (Capabilities|undefined)})} capabilities The desired
663-
* capabilities for the new session.
660+
* @param {!Capabilities} capabilities The desired capabilities for the new
661+
* session.
664662
* @param {(function(this: void): ?)=} onQuit A callback to invoke when
665663
* the newly created session is terminated. This should be used to clean
666664
* up any resources associated with the session.
@@ -669,24 +667,12 @@ class WebDriver {
669667
static createSession(executor, capabilities, onQuit = undefined) {
670668
let cmd = new command.Command(command.Name.NEW_SESSION);
671669

672-
if (capabilities && (capabilities.desired || capabilities.required)) {
673-
// For OSS remote ends.
674-
cmd.setParameter('desiredCapabilities', capabilities.desired);
675-
cmd.setParameter('requiredCapabilities', capabilities.required);
676-
// For W3C remote ends.
677-
let merged = new Capabilities(capabilities.desired);
678-
merged.merge(capabilities.required);
679-
cmd.setParameter('capabilities', {
680-
alwaysMatch: WebDriver.filterNonW3CCaps_(merged),
681-
});
682-
} else {
683-
// For OSS remote ends.
684-
cmd.setParameter('desiredCapabilities', capabilities);
685-
// For W3C remote ends.
686-
cmd.setParameter('capabilities', {
687-
alwaysMatch: WebDriver.filterNonW3CCaps_(capabilities),
688-
});
689-
}
670+
// For OSS remote ends.
671+
cmd.setParameter('desiredCapabilities', capabilities);
672+
// For W3C remote ends.
673+
cmd.setParameter('capabilities', {
674+
alwaysMatch: filterNonW3CCaps(capabilities),
675+
});
690676

691677
let session = executeCommand(executor, cmd);
692678
if (typeof onQuit === 'function') {
@@ -697,23 +683,6 @@ class WebDriver {
697683
return new this(session, executor, onQuit);
698684
}
699685

700-
/**
701-
* @param {!Capabilities} capabilities A capabilities object.
702-
* @return {!Capabilities} A copy of the parameter capabilities, omitting
703-
* capability names that are not valid W3C names.
704-
* @private
705-
*/
706-
static filterNonW3CCaps_(capabilities) {
707-
let newCaps = new Capabilities(capabilities);
708-
for (let k of newCaps.keys()) {
709-
// Any key containing a colon is a vendor-prefixed capability.
710-
if (!(W3C_CAPABILITY_NAMES.has(k) || k.indexOf(':') >= 0)) {
711-
newCaps.delete(k);
712-
}
713-
}
714-
return newCaps;
715-
}
716-
717686
/** @override */
718687
async execute(command) {
719688
command.setParameter('sessionId', this.session_);

javascript/node/selenium-webdriver/test/lib/webdriver_test.js

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,26 +222,6 @@ describe('WebDriver', function() {
222222
return driver.getSession().then(v => assert.strictEqual(v, aSession));
223223
});
224224

225-
it('handles desired and required capabilities', function() {
226-
let aSession = new Session(SESSION_ID, {'browserName': 'firefox'});
227-
let executor = new FakeExecutor().
228-
expect(CName.NEW_SESSION).
229-
withParameters({
230-
'desiredCapabilities': {'foo:x': 'bar'},
231-
'requiredCapabilities': {'bim:x': 'baz'},
232-
'capabilities': {
233-
'alwaysMatch': {'foo:x': 'bar', 'bim:x': 'baz'},
234-
},
235-
}).
236-
andReturnSuccess(aSession).
237-
end();
238-
239-
let desired = new Capabilities().set('foo:x', 'bar');
240-
let required = new Capabilities().set('bim:x', 'baz');
241-
var driver = WebDriver.createSession(executor, {desired, required});
242-
return driver.getSession().then(v => assert.strictEqual(v, aSession));
243-
});
244-
245225
it('drops non-W3C capability names from W3C capabilities', function() {
246226
let aSession = new Session(SESSION_ID, {'browserName': 'firefox'});
247227
let executor = new FakeExecutor().

0 commit comments

Comments
 (0)