From bc30941eb310b4546017106fde724acc01fc4ecd Mon Sep 17 00:00:00 2001 From: Ankur Narkhede <84451419+ankur-lt@users.noreply.github.com> Date: Mon, 22 Nov 2021 10:19:58 +0530 Subject: [PATCH] Added ability to pass useHostName and secure via openBrowser API and bumped version to 1.2.8 for patch release (#2380) Signed-off-by: Ankur Narkhede --- lib/config.js | 2 ++ lib/connection.js | 2 ++ lib/handlers/targetHandler.js | 4 ++++ lib/taiko.js | 8 ++++++-- package.json | 2 +- test/unit-tests/config.test.js | 4 ++++ 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/config.js b/lib/config.js index 4cc03cd8d..32dea6acd 100644 --- a/lib/config.js +++ b/lib/config.js @@ -22,6 +22,8 @@ const defaultConfig = { : process.env.TAIKO_HIGHLIGHT_ON_ACTION || 'true', blockAlignment: 'nearest', inlineAlignment: 'nearest', + useHostName: false, + secure: false, }; const setConfig = (options) => { for (const key in options) { diff --git a/lib/connection.js b/lib/connection.js index da1fe42e2..77b3675b2 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -70,6 +70,8 @@ const initCRI = async (target, n, options = {}) => { target, host: defaultConfig.host, port: defaultConfig.port, + useHostName: defaultConfig.useHostName, + secure: defaultConfig.secure, alterPath: defaultConfig.alterPath, local: defaultConfig.local, }); diff --git a/lib/handlers/targetHandler.js b/lib/handlers/targetHandler.js index ac12dfd2b..618f15716 100644 --- a/lib/handlers/targetHandler.js +++ b/lib/handlers/targetHandler.js @@ -26,6 +26,8 @@ const createdSessionListener = async (client, currentTarget) => { await cri({ host: defaultConfig.host, port: defaultConfig.port, + useHostName: defaultConfig.useHostName, + secure: defaultConfig.secure, alterPath: defaultConfig.alterPath, local: defaultConfig.local, target: defaultConfig.browserDebugUrl, @@ -191,6 +193,8 @@ const getFirstAvailablePageTarget = async () => { await cri({ host: defaultConfig.host, port: defaultConfig.port, + useHostName: defaultConfig.useHostName, + secure: defaultConfig.secure, alterPath: defaultConfig.alterPath, local: defaultConfig.local, target: defaultConfig.browserDebugUrl, diff --git a/lib/taiko.js b/lib/taiko.js index 3c2bca6f9..966adec45 100644 --- a/lib/taiko.js +++ b/lib/taiko.js @@ -68,6 +68,8 @@ module.exports.emitter = descEvent; * @param {string} [options.host='127.0.0.1'] - Remote host to connect to. * @param {string} [options.target] - Determines which target the client should interact.(https://github.com/cyrus-and/chrome-remote-interface#cdpoptions-callback) * @param {number} [options.port=0] - Remote debugging port, if not given connects to any open port. + * @param {number} [options.useHostName=false] - If the browser should be called using the hostname itself or with IP address + * @param {number} [options.secure=false] - HTTPS/WSS frontend. Defaults to false. * @param {boolean} [options.ignoreCertificateErrors=true] - Option to ignore certificate errors. * @param {boolean} [options.observe=false] - Option to run each command after a delay. Useful to observe what is happening in the browser. * @param {number} [options.observeTime=3000] - Option to modify delay time for observe mode. Accepts value in milliseconds. @@ -89,6 +91,8 @@ module.exports.openBrowser = async ( if ((options.host && options.port) || options.target) { defaultConfig.host = options.host; defaultConfig.port = options.port; + defaultConfig.useHostName = options.useHostName; + defaultConfig.secure = options.secure; defaultConfig.browserDebugUrl = options.target; defaultConfig.connectedToRemoteBrowser = true; } else { @@ -1249,7 +1253,7 @@ async function mouseAction(selector, action, coordinates, options = {}) { * Scrolls the page to the given element. * The alignment parameters can be overridden, see below. * Tthe possible values reference are available at the https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollIntoView. - * + * * * @example * await scrollTo('Get Started') @@ -1266,7 +1270,7 @@ async function mouseAction(selector, action, coordinates, options = {}) { * @param {number} [options.waitForStart = 100] - time to wait for navigation to start. Accepts value in milliseconds. * @param {string} [options.blockAlignment = 'nearest'] - Defines vertical alignment. * @param {string} [options.inlineAligment = 'nearest'] - Defines horizontal alignment. - * + * * @returns {Promise} */ module.exports.scrollTo = async (selector, options = {}) => { diff --git a/package.json b/package.json index 1c3272e4e..4c78c2613 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "$schema": "http://json.schemastore.org/package", "name": "taiko", - "version": "1.2.7", + "version": "1.2.8", "description": "Taiko is a Node.js library for automating Chromium based browsers", "main": "bin/taiko.js", "bin": { diff --git a/test/unit-tests/config.test.js b/test/unit-tests/config.test.js index 5ff740b91..1cace208c 100644 --- a/test/unit-tests/config.test.js +++ b/test/unit-tests/config.test.js @@ -36,6 +36,8 @@ describe('Config tests', () => { observeTime: 2, retryInterval: 2, retryTimeout: 2, + secure: false, + useHostName: false, waitForNavigation: false, waitForEvents: ['firstContentfulPaint'], criConnectionRetries: 50, @@ -244,6 +246,8 @@ describe('Config tests', () => { observeTime: 5000, retryInterval: 100, retryTimeout: 10000, + secure: false, + useHostName: false, waitForNavigation: true, waitForEvents: [], criConnectionRetries: 50,