From eacf4d62f9715be006ae0675d111a2e1fad5beee Mon Sep 17 00:00:00 2001 From: erla-softrams Date: Wed, 24 Jul 2024 09:07:16 -0400 Subject: [PATCH 1/6] file-download-path-set: updates to file download path on new opened tab/window --- lib/_init.js | 4 +--- lib/page_steps.js | 2 ++ package.json | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/_init.js b/lib/_init.js index 302992e..f9312ba 100644 --- a/lib/_init.js +++ b/lib/_init.js @@ -22,7 +22,6 @@ const download_dir = process.env.file_download_path; beforeSuite(async () => { if (!browser_for_each_scenario || browser_for_each_scenario === 'false') { await taiko.openBrowser({ headless: headless === 'true', args: browser_args}); - await setFileDownloadPath(); } taiko.setConfig({ navigationTimeout: Number((process.env.navigation_timeout || taiko.getConfig("navigationTimeout"))), @@ -40,7 +39,6 @@ beforeScenario(async context => { headless: headless === 'true', args: browser_args }); - await setFileDownloadPath(); } }); @@ -82,7 +80,7 @@ gauge.customScreenshotWriter = async function () { return path.basename(screenshotFilePath); }; -async function setFileDownloadPath() { +exports.setFileDownloadPath = async () => { if (download_dir) { const file_download_dir = path.isAbsolute(`${download_dir}`) ? `${download_dir}` : process.cwd() + `/${download_dir}`; var downloadPath = path.resolve(__dirname, file_download_dir); diff --git a/lib/page_steps.js b/lib/page_steps.js index 266abcd..cc4fe89 100644 --- a/lib/page_steps.js +++ b/lib/page_steps.js @@ -6,6 +6,7 @@ const selectors = require("./_selectors"); const helpers = require("./_helpers"); const path = require("path"); const { getPageElement, checkElementState, scrollToElementView } = require("./_pageElement"); +const { setFileDownloadPath } = require("./_init"); step(["Goto ", "Open ", "Goto in new tab", "Open in new tab"], async url => { let navigateUrl = process.env[url] ? process.env[url] : (url ? url : process.env.APP_ROOT_URL); @@ -20,6 +21,7 @@ step(["Goto ", "Open ", "Goto in new tab", "Open in new ta const response = await taiko.goto(navigateUrl); assert.strictEqual(response.status.code, 200); } + setFileDownloadPath(); }); step(["Switch to ", "Switch to window"], async urlTitle => { diff --git a/package.json b/package.json index 2c090ed..48a60ca 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@softrams/gauge-taiko-steps", - "version": "0.1.8", + "version": "0.1.9", "description": "Implementation of common test steps with Taiko driver for writing tests with Gauge framework", "main": "index.js", "scripts": { From f1c5617f24d6638f62ea2e0af10628378939edc3 Mon Sep 17 00:00:00 2001 From: erla-softrams Date: Wed, 24 Jul 2024 09:09:18 -0400 Subject: [PATCH 2/6] file-download-path-set: updates to file download path on new opened tab/window --- lib/_helpers.js | 8 ++++++++ lib/_init.js | 8 -------- lib/page_steps.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/_helpers.js b/lib/_helpers.js index 5f80cea..003a3c0 100644 --- a/lib/_helpers.js +++ b/lib/_helpers.js @@ -28,6 +28,14 @@ exports.getValue = value => { return String(getDynamicValue(value)); }; +exports.setFileDownloadPath = async () => { + if (download_dir) { + const file_download_dir = path.isAbsolute(`${download_dir}`) ? `${download_dir}` : process.cwd() + `/${download_dir}`; + var downloadPath = path.resolve(__dirname, file_download_dir); + await taiko.client().send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: downloadPath }); + } +}; + const getDynamicValue = value => { return process.env[value] || gauge.dataStore.scenarioStore.get(value) || getDate(value) || getFakeData(value) || value; }; diff --git a/lib/_init.js b/lib/_init.js index f9312ba..34c0f7b 100644 --- a/lib/_init.js +++ b/lib/_init.js @@ -79,11 +79,3 @@ gauge.customScreenshotWriter = async function () { await taiko.screenshot({ path: screenshotFilePath, fullPage: false }); return path.basename(screenshotFilePath); }; - -exports.setFileDownloadPath = async () => { - if (download_dir) { - const file_download_dir = path.isAbsolute(`${download_dir}`) ? `${download_dir}` : process.cwd() + `/${download_dir}`; - var downloadPath = path.resolve(__dirname, file_download_dir); - await taiko.client().send('Page.setDownloadBehavior', { behavior: 'allow', downloadPath: downloadPath }); - } -}; diff --git a/lib/page_steps.js b/lib/page_steps.js index cc4fe89..a9f7bec 100644 --- a/lib/page_steps.js +++ b/lib/page_steps.js @@ -6,7 +6,7 @@ const selectors = require("./_selectors"); const helpers = require("./_helpers"); const path = require("path"); const { getPageElement, checkElementState, scrollToElementView } = require("./_pageElement"); -const { setFileDownloadPath } = require("./_init"); +const { setFileDownloadPath } = require("./_helpers"); step(["Goto ", "Open ", "Goto in new tab", "Open in new tab"], async url => { let navigateUrl = process.env[url] ? process.env[url] : (url ? url : process.env.APP_ROOT_URL); From 829b547a4d3308db2becb4a438ede1e1b2ce8a7d Mon Sep 17 00:00:00 2001 From: erla-softrams Date: Wed, 24 Jul 2024 10:48:17 -0400 Subject: [PATCH 3/6] file-download-path-set: updates to file download path on new opened tab/window --- lib/_helpers.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/_helpers.js b/lib/_helpers.js index 003a3c0..668f047 100644 --- a/lib/_helpers.js +++ b/lib/_helpers.js @@ -1,6 +1,8 @@ const { faker } = require("@faker-js/faker"); const moment = require("moment"); +const download_dir = process.env.file_download_path; + exports.parseString = text => { let result = text; try { From d5446afa4246dfd40408c99196c719574082e537 Mon Sep 17 00:00:00 2001 From: erla-softrams Date: Wed, 24 Jul 2024 10:50:42 -0400 Subject: [PATCH 4/6] file-download-path-set: updates to file download path on new opened tab/window --- lib/_helpers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/_helpers.js b/lib/_helpers.js index 668f047..b5b5211 100644 --- a/lib/_helpers.js +++ b/lib/_helpers.js @@ -1,4 +1,5 @@ const { faker } = require("@faker-js/faker"); +const path = require("path"); const moment = require("moment"); const download_dir = process.env.file_download_path; From 0888213883e0121e64ac6ee52902a107763cf5f7 Mon Sep 17 00:00:00 2001 From: erla-softrams Date: Wed, 24 Jul 2024 12:28:26 -0400 Subject: [PATCH 5/6] file-download-path-set: updates to file download path on new opened tab/window --- lib/_helpers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/_helpers.js b/lib/_helpers.js index b5b5211..3571bc9 100644 --- a/lib/_helpers.js +++ b/lib/_helpers.js @@ -1,4 +1,5 @@ const { faker } = require("@faker-js/faker"); +const taiko = require("taiko"); const path = require("path"); const moment = require("moment"); From 8df5c29899e8ba5f8788ac87d6bc56b039e1c622 Mon Sep 17 00:00:00 2001 From: erla-softrams Date: Wed, 24 Jul 2024 14:53:22 -0400 Subject: [PATCH 6/6] file-download-path-set: updates to file download path on new opened tab/window --- lib/_helpers.js | 3 +-- lib/page_steps.js | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/_helpers.js b/lib/_helpers.js index 3571bc9..8058932 100644 --- a/lib/_helpers.js +++ b/lib/_helpers.js @@ -1,5 +1,4 @@ const { faker } = require("@faker-js/faker"); -const taiko = require("taiko"); const path = require("path"); const moment = require("moment"); @@ -32,7 +31,7 @@ exports.getValue = value => { return String(getDynamicValue(value)); }; -exports.setFileDownloadPath = async () => { +exports.setFileDownloadPath = async (taiko) => { if (download_dir) { const file_download_dir = path.isAbsolute(`${download_dir}`) ? `${download_dir}` : process.cwd() + `/${download_dir}`; var downloadPath = path.resolve(__dirname, file_download_dir); diff --git a/lib/page_steps.js b/lib/page_steps.js index a9f7bec..7755c57 100644 --- a/lib/page_steps.js +++ b/lib/page_steps.js @@ -21,7 +21,7 @@ step(["Goto ", "Open ", "Goto in new tab", "Open in new ta const response = await taiko.goto(navigateUrl); assert.strictEqual(response.status.code, 200); } - setFileDownloadPath(); + setFileDownloadPath(taiko); }); step(["Switch to ", "Switch to window"], async urlTitle => {