diff --git a/Browser/keywords/promises.py b/Browser/keywords/promises.py index c712d999e..acfdc2503 100644 --- a/Browser/keywords/promises.py +++ b/Browser/keywords/promises.py @@ -149,6 +149,8 @@ def promise_to_wait_for_download( With default filepath downloaded files are deleted when Context the download happened in is closed. + If browser is connected remotely with `Connect To Browser` then ``saveAs`` must be set to store it locally where the browser runs! + | =Arguments= | =Description= | | ``saveAs`` | Defines path where the file is saved persistently. File will also temporarily be saved in playwright context's default download location. If empty, generated unique path (GUID) is used and file is deleted when the context is closed. | | ``wait_for_finished`` | If true, promise will wait for download to finish. If false, promise will resolve immediately after download has started. | diff --git a/atest/test/02_Content_Keywords/files.robot b/atest/test/02_Content_Keywords/files.robot index 6cb231065..d1e690263 100644 --- a/atest/test/02_Content_Keywords/files.robot +++ b/atest/test/02_Content_Keywords/files.robot @@ -8,6 +8,7 @@ Force Tags slow *** Variables *** ${CUSTOM_DL_PATH} = ${CURDIR}/download_file +${ORIGINAL_TIMEOUT} 1s *** Test Cases *** Upload Upload_test_file @@ -123,7 +124,35 @@ Wait For Download Relative To downloadsPath File Should Exist ${OUTPUT DIR}/test_download_file_saveAs.js Remove File ${download_file_object}[saveAs] +Wait For Download with Remote Browser + [Setup] Launch and Connect To Remote Browser + New Context acceptDownloads=True + New Page ${LOGIN_URL} + ${dl_promise} = Promise To Wait For Download saveAs=persistent_downloads + Click \#file_download + ${file_object} = Wait For ${dl_promise} + File Should Exist ${file_object}[saveAs] + Should Be Equal ${file_object}[suggestedFilename] test_download_file.js + Remove File ${file_object}[saveAs] + +Wait For Download with Remote Browser Without SaveAs + [Setup] Launch and Connect To Remote Browser + New Context acceptDownloads=True + New Page ${LOGIN_URL} + ${dl_promise} = Promise To Wait For Download + Click \#file_download + TRY + ${file_object} = Wait For ${dl_promise} + EXCEPT *Path is not available when connecting remotely. Use saveAs() to save a local copy. type=GLOB + Log Correct Error + END + *** Keywords *** +Launch and Connect To Remote Browser + ${ws} Launch Browser Server headless=${HEADLESS} + Connect To Browser wsEndpoint=${ws} + Set Browser Timeout 90 seconds + Set Library Timeout ${open_browsers} = Get Browser Ids IF $open_browsers == [] @@ -132,7 +161,6 @@ Set Library Timeout ${current_contexts} = Get Context Ids Active Active IF $current_contexts == [] New Context ${timeout} = Set Browser Timeout 90 seconds - Set Suite Variable ${ORIGINAL_TIMEOUT} 1s Restore Library Timeout Set Browser Timeout ${ORIGINAL_TIMEOUT} diff --git a/node/playwright-wrapper/network.ts b/node/playwright-wrapper/network.ts index dab7c83c1..6d0a7dd12 100644 --- a/node/playwright-wrapper/network.ts +++ b/node/playwright-wrapper/network.ts @@ -147,7 +147,6 @@ export async function _waitForDownload( } } const fileName = downloadObject.suggestedFilename(); - const pathPromise = downloadObject.path(); if (!waitForFinished) { const downloadID = uuidv4(); const activeIndexedPage = state.activeBrowser?.page; @@ -170,25 +169,22 @@ export async function _waitForDownload( throw new Error('No active page found'); } } - let downloadPath; if (downloadTimeout > 0) { - downloadPath = await Promise.race([ - pathPromise, + const readStream = await Promise.race([ + downloadObject.createReadStream(), new Promise((resolve) => setTimeout(resolve, downloadTimeout)), ]); - if (!downloadPath) { + if (!readStream) { downloadObject.cancel(); throw new Error('Download failed, Timeout exceeded.'); } - } else { - downloadPath = await pathPromise; } let filePath; if (saveAs) { await downloadObject.saveAs(saveAs); filePath = path.resolve(saveAs); } else { - filePath = downloadPath; + filePath = await downloadObject.path(); } logger.info('suggestedFilename: ' + fileName + ' saveAs path: ' + filePath); return jsonResponse(