From 9a767b5f25e2bffc1df8fc33212a0aa6ba6c44bb Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Wed, 29 Sep 2021 19:57:14 +0530 Subject: [PATCH] [js] Restore withCapabilities() to ensure backward compatibility --- javascript/node/selenium-webdriver/index.js | 2 +- .../selenium-webdriver/test/builder_test.js | 27 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/javascript/node/selenium-webdriver/index.js b/javascript/node/selenium-webdriver/index.js index 7063190640abd..317cbea441997 100644 --- a/javascript/node/selenium-webdriver/index.js +++ b/javascript/node/selenium-webdriver/index.js @@ -318,7 +318,7 @@ class Builder { } /** - * @deprecated Since Selenium 4.0 withCapabilities is deprecated, use set*Options instead where * is the browser(eg setChromeOptions) + * Recommended way is to use set*Options where * is the browser(eg setChromeOptions) * * Sets the desired capabilities when requesting a new session. This will * overwrite any previously set capabilities. diff --git a/javascript/node/selenium-webdriver/test/builder_test.js b/javascript/node/selenium-webdriver/test/builder_test.js index 0bcccdb767e75..911c2f7c53984 100644 --- a/javascript/node/selenium-webdriver/test/builder_test.js +++ b/javascript/node/selenium-webdriver/test/builder_test.js @@ -69,3 +69,30 @@ test.suite(function (env) { }) } }) + +describe('Builder', function () { + describe('catches incorrect use of browser options class', function () { + function test(key, options) { + it(key, async function () { + let builder = new Builder().withCapabilities( + new Capabilities() + .set('browserName', 'fake-browser-should-not-try-to-start') + .set(key, new options()) + ) + try { + let driver = await builder.build() + await driver.quit() + return Promise.reject(Error('should have failed')) + } catch (ex) { + if (!(ex instanceof error.InvalidArgumentError)) { + throw ex + } + } + }) + } + + test('chromeOptions', chrome.Options) + test('moz:firefoxOptions', firefox.Options) + test('safari.options', safari.Options) + }) +}) \ No newline at end of file