Rayrun
← Back to Discord Forum

How to Read data from a downloaded excel to verify the contents in Playwright?

Hi team, My requirement is after I download a file using Playwright, I would like to verify the contents from the downloaded file. How would I achieve that using Playwright?

This thread is trying to answer question "How can I read and verify the contents of a downloaded .xlsx file using Playwright?"

12 replies

Depends on what type of file it is but most likely you will need 3rd party library for that

The file type is .xlsx. I tried using the SheetJS library but it did not work. Could you assist me in this ?

@skorp32

🤷‍♀️ don't have experience with such files, but there should be more libs to parse it

patrickdoering
patrickdoering

@qb1225 I used xlsx for that.

@patrickdoering Could you specify the name of the library?

yes, this is the exact one which I used. However, I am getting the error that File cannot be open

@patrickdoering Have you encountered such issue while trying to readFile

patrickdoering
patrickdoering

Nope it worked fine for me.

okay, thank you @patrickdoering

patrickdoering
patrickdoering

That is how my code looks like:

const workbook = xlsx.readFile(filePath);  
let workbook_sheet = workbook.SheetNames;               
let workbook_response = xlsx.utils.sheet_to_json(        
  workbook.Sheets[workbook_sheet[0]]
);
const excelString = JSON.stringify(workbook_response);

Related Discord Threads

TwitterGitHubLinkedIn
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.