1

I have a scenario where I need to download a file using Playwright. When I download, I get the file in a zip format. How can I validate the file format of the actual file that is zipped. While validating manually, I can extract it and see the file format. How can I do it with Playwright automation? (I'm working with Javascript)

1 Answers1

0

You may use nodeJS fs & unzip modules for verifying file extensions inside zip file.

const unzip = require('unzip'),
    fs    = require('fs'),
    path = require('path'),
    inputFileName = '/home/user/Downloads/SomeFile.zip'; // zip file path 

fs.createReadStream(inputFileName)
    .pipe(unzip.Parse())
    .on('entry', (entry) => {
        const rest_file_path = ['.js', '.exe', '.zip'],
            extension = path.extname(entry.path);
        if (rest_file_path.includes(extension)) {
            console.log(`Found the expected file extensions`) 

        }
        
    });

Reference: https://www.npmjs.com/package/unzip

Vishal Aggarwal
  • 1,929
  • 1
  • 13
  • 23