← Back to Discord Forum

Help renaming downloads made by playwright

Hi! I am having a really tough time renaming 4 files downloaded using playwright to my custom names. The files have to end in ".csv" for them to be accepted into a google docs clone Im using. I have used suggested filename but it renames all four to the exact same name and then when uploading them to the google docs clone it gets them confused. I tried an object literal like:

const filePath4 = 4${download4.suggestedFilename()} However I get an error saying this path doesnt exist. Does anyone know how I could rename my file to a custom name?


This thread is trying to answer question "How can I rename my file to a custom name using playwright?"

3 replies

Try something like this:

const [download] = await Promise.all([
   this.page.getByText('foo bar baz').click()]
const downloadedFileName = 'downloads/yourfile.csv';
await download.saveAs(downloadedFileName);
@.gleedo: thank you very much. When i console log the download path i get Promise { <pending> }

thank you very much. When i console log the download path i get Promise { <pending> }

is there any way to resolve this issue?

Related Discord Threads

AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.