Skip to content

Commit

Permalink
Merge pull request #51 from softrams/file-download-path
Browse files Browse the repository at this point in the history
File download path
  • Loading branch information
mkmurali authored Jul 24, 2024
2 parents e452f16 + 8b35a84 commit 90f46c8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
11 changes: 11 additions & 0 deletions lib/_helpers.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const { faker } = require("@faker-js/faker");
const path = require("path");
const moment = require("moment");

const download_dir = process.env.file_download_path;

exports.parseString = text => {
let result = text;
try {
Expand Down Expand Up @@ -28,6 +31,14 @@ exports.getValue = value => {
return String(getDynamicValue(value));
};

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);
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;
};
Expand Down
10 changes: 0 additions & 10 deletions lib/_init.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"))),
Expand All @@ -40,7 +39,6 @@ beforeScenario(async context => {
headless: headless === 'true',
args: browser_args
});
await setFileDownloadPath();
}
});

Expand Down Expand Up @@ -81,11 +79,3 @@ gauge.customScreenshotWriter = async function () {
await taiko.screenshot({ path: screenshotFilePath, fullPage: false });
return path.basename(screenshotFilePath);
};

async function setFileDownloadPath() {
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 });
}
};
2 changes: 2 additions & 0 deletions lib/page_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -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("./_helpers");

step(["Goto <url>", "Open <url>", "Goto <url> in new tab", "Open <url> in new tab"], async url => {
let navigateUrl = process.env[url] ? process.env[url] : (url ? url : process.env.APP_ROOT_URL);
Expand All @@ -20,6 +21,7 @@ step(["Goto <url>", "Open <url>", "Goto <url> in new tab", "Open <url> in new ta
const response = await taiko.goto(navigateUrl);
assert.strictEqual(response.status.code, 200);
}
setFileDownloadPath(taiko);
});

step(["Switch to <urlTitle>", "Switch to <urlTitle> window"], async urlTitle => {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down

0 comments on commit 90f46c8

Please sign in to comment.