Our AI can verify the contents of a downloaded file. We currently support xlsx, pdf, and csv file types.

1. Get the download button locator

In order to handle the download, you will need a locator for the button that downloads the file. You can get this locator by recording clicking or hovering on the button, which will create an action in the step list. Double click on the element name inside the generated action, and copy the locator.

Get download button locator

2. Add download handling code

Create a new code block and add the following code, replacing the locator with the one you just found, and changing the variable name of the downloaded file to your liking.
If you have more than one tab open, you will need to change page to the name of the page with the download button, eg. page2
For pdf and csv:
const [download] = await Promise.all([
  page.waitForEvent('download'),
  // TODO: Modify the locator
  page.locator('<enter the locator here>').click(),
]);
const stream = await download.createReadStream();

const chunks = [];
for await (const chunk of stream) {
  chunks.push(chunk);
}
const textData = Buffer.concat(chunks);

// TODO: change the variable name here if needed
VARS.downloadedFile = textData
For Excel files:
const [download] = await Promise.all([
  page.waitForEvent('download'),
  // TODO: Modify the locator here
  page.locator('<change this locator>').click(),
]);
const stream = await download.createReadStream();

const chunks = [];
for await (const chunk of stream) {
  chunks.push(chunk);
}
const buffer = Buffer.concat(chunks);

// Parse the Excel file and get the first sheet
const workbook = XLSX.read(buffer, { type: 'buffer' });
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];

// TODO: change the variable name here if needed
VARS.spreadsheetData = XLSX.utils.sheet_to_json(worksheet, { header: 1 }); // Get data as array
If you want to verify the filename of the downloaded file, you can access it like this: download.suggestedFilename();

The modified code using my locator

3. Add AI assertion

Add an AI assertion that references the variable name from the code block to verify the contents of the downloaded file.
You can use the ‘Disabled’ screenshot type to force the AI to only look at the available variables, and not the page.

A sample assertion

4. Run the test

Run the test to the end. As you can see, the AI was able to verify the contents of the Excel file.

AI successfully verified the contents

5. Clean up

Delete or skip the first action you added to get the locator.