Skip to content

Commit f1be8f4

Browse files
committed
chore(release v1.22.2): update downloadFile function for improved remote compatibility, return suggested filename, and update dependencies
1 parent ef8f805 commit f1be8f4

4 files changed

Lines changed: 48 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# Changelog
22

3+
## [1.22.2] - 2026-02-10
4+
5+
### Fixed
6+
7+
- **downloadFile (action-utils):** Removed use of `download.path()`, which is unavailable when connecting to a remote browser (e.g. Docker or cloud). The method now uses only `saveAs(savePath)`, so file downloads work both locally and when connecting remotely.
8+
9+
### Updated
10+
11+
- **downloadFile (action-utils):** Now returns the suggested filename (or a fallback from `savePath`) for use in assertions or logging. Added explicit failure check before save and improved JSDoc and examples.
12+
313
## [1.22.1] - 2026-02-09
414

515
### Breaking changes

package-lock.json

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vasu-playwright-utils",
3-
"version": "1.22.1",
3+
"version": "1.22.2",
44
"description": "Playwright Typescript Library with reusable utilities",
55
"main": "./dist/src/vasu-playwright-lib/index.js",
66
"types": "./dist/src/vasu-playwright-lib/index.d.ts",
@@ -47,7 +47,7 @@
4747
},
4848
"dependencies": {
4949
"@eslint/js": "^9.39.2",
50-
"@types/node": "^25.2.2",
50+
"@types/node": "^25.2.3",
5151
"@typescript-eslint/eslint-plugin": "^8.55.0",
5252
"@typescript-eslint/parser": "^8.55.0",
5353
"cross-env": "^10.1.0",

src/vasu-playwright-lib/utils/action-utils.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -401,19 +401,35 @@ export async function doubleClick(input: string | Locator, options?: DoubleClick
401401
}
402402

403403
/**
404-
* Downloads a file from a specified element.
405-
* @param {string | Locator} input - The element to download the file from.
406-
* @param {string} path - The path to save the downloaded file to.
404+
* Triggers a file download by clicking the given element and saves the file to `savePath`.
405+
*
406+
* Uses `saveAs()` only (no `download.path()`), so it works locally and when connecting
407+
* to a remote browser (e.g. Docker or cloud).
408+
*
409+
* @param {string | Locator} input - Selector or locator for the element that starts the download (e.g. download button).
410+
* @param {string} savePath - Full path where the file should be saved along with file extension
411+
* @returns {Promise<string>}The suggested filename from the response, or the last segment of `savePath` if empty. Use for assertions or logging.
412+
* @throws If the element is not found, the click fails, the download fails, or save fails.
413+
* @example
414+
* const filename = await downloadFile('#download-btn', '/tmp/report.pdf');
415+
* expect(filename).toBe('report.pdf');
416+
*
417+
* const filename = await downloadFile(myLocator, path.join(downloadDir, 'file.zip'), { timeout: 30000 });
407418
*/
408-
export async function downloadFile(input: string | Locator, path: string, options?: ClickOptions): Promise<void> {
419+
export async function downloadFile(input: string | Locator, savePath: string, options?: ClickOptions): Promise<string> {
409420
const locator = await getLocatorWithStableAndVisibleOptions(input, options);
410421
const downloadPromise = getPage().waitForEvent('download');
411422
await click(locator, options);
412423
const download = await downloadPromise;
413-
// Wait for the download process to complete
414-
console.info(await download.path());
415-
// Save downloaded file somewhere
416-
await download.saveAs(path);
424+
425+
const failure = await download.failure();
426+
if (failure) {
427+
throw new Error(`Download failed: ${failure}`);
428+
}
429+
430+
await download.saveAs(savePath);
431+
const suggestedFilename = download.suggestedFilename();
432+
return suggestedFilename;
417433
}
418434

419435
/**

0 commit comments

Comments
 (0)