From 18c94547c0118877afdf7c1a4f9fe624c582391e Mon Sep 17 00:00:00 2001 From: Salvador Cabrera Lozano Date: Tue, 20 Apr 2021 11:51:01 -0500 Subject: [PATCH] [js] Add windowTypes option support for ChromiumDriver (#7897) * [js] windowTypes option support for ChromiumDriver Adds support for setting windowTypes option for ChromeDriver, which allows getting an extra set of window type handles like webview handles. For more info, see: https://chromedriver.chromium.org/capabilities * [js] Add test for windowTypes option support for ChromiumDriver * [js] Replacing deepEqual(deprecated) with deepStrictEqual Co-authored-by: Sri Harsha <12621691+JS31096@users.noreply.github.com> Co-authored-by: Sri Harsha --- javascript/node/selenium-webdriver/chromium.js | 16 ++++++++++++++++ .../test/chrome/options_test.js | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/javascript/node/selenium-webdriver/chromium.js b/javascript/node/selenium-webdriver/chromium.js index 857f1386f619a..89bf3dce25a09 100644 --- a/javascript/node/selenium-webdriver/chromium.js +++ b/javascript/node/selenium-webdriver/chromium.js @@ -549,6 +549,22 @@ class Options extends Capabilities { return this } + /** + * Sets a list of the window types that will appear when getting window + * handles. For access to elements, include "webview" in the list. + * @param {...(string|!Array)} args The window types that will appear + * when getting window handles. + * @return {!Options} A self reference. + */ + windowTypes(...args) { + let windowTypes = (this.options_.windowTypes || []).concat(...args); + if (windowTypes.length) { + this.options_.windowTypes = windowTypes; + } + return this; + } + + /** * Converts this instance to its JSON wire protocol representation. Note this * function is an implementation not intended for general use. diff --git a/javascript/node/selenium-webdriver/test/chrome/options_test.js b/javascript/node/selenium-webdriver/test/chrome/options_test.js index 352a7e4c0fa87..a20886113751d 100644 --- a/javascript/node/selenium-webdriver/test/chrome/options_test.js +++ b/javascript/node/selenium-webdriver/test/chrome/options_test.js @@ -91,6 +91,24 @@ describe('chrome.Options', function () { ) }) }) + + describe('windowTypes', function() { + it('takes var_args', function() { + let options = new chrome.Options(); + assert.strictEqual(options.options_.windowTypes, undefined); + + options.windowTypes('a', 'b'); + assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b']); + }) + + it('flattens input arrays', function() { + let options = new chrome.Options(); + assert.strictEqual(options.options_.windowTypes, undefined); + + options.windowTypes(['a', 'b'], 'c', [1, 2], 3); + assert.deepStrictEqual(options.options_.windowTypes, ['a', 'b', 'c', 1, 2, 3]); + }) + }) }) test.suite(