Our AI can verify the contents of a downloaded file. We currently support pdf, csv, and all MS Office 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.
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

PDF Files

Method 1: Download from page
const [download] = await Promise.all([
  page.waitForEvent('download'),
  // TODO: Replace with your actual download button locator
  page.locator('<change this locator>').click(),
]);

// Extract PDF content from the download stream
const stream = await download.createReadStream();
const chunks = [];
for await (const chunk of stream) {
  chunks.push(chunk);
}
const pdfBuffer = Buffer.concat(chunks);
const pdfUint8Array = Uint8Array.from(pdfBuffer);

// Load the PDF file into a PDF.js document
const pdf = await unpdf.getDocumentProxy(pdfUint8Array);

// Extract text from all pages and merge into single string
const { totalPages, text } = await unpdf.extractText(pdf, { mergePages: true });
VARS.pdfText = text;
Method 2: Fetch from URL
const pdfResponse = await fetch(
  // TODO: Replace with your actual PDF URL (should end with .pdf)
  '<change this URL>',
);

// Load the PDF file into a PDF.js document
const pdf = await unpdf.getDocumentProxy(await pdfResponse.arrayBuffer());

// Extract text from all pages and merge into single string
const { totalPages, text } = await unpdf.extractText(pdf, { mergePages: true });
VARS.pdfText = text;

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

The modified code using my locator

Office Documents (DOCX, PPTX)

This method parses Office documents and returns plain text. For Excel files, use the XLSX package above to preserve formatting and structure.
const [download] = await Promise.all([
  page.waitForEvent('download'),
  // TODO: Modify the locator here
  page.locator('<change this locator>').click(),
]);

const downloadedFileName = download.suggestedFilename();

// Save the download to a temporary file
const filePath = `./temp/${downloadedFileName}`;
await download.saveAs(filePath);

// Now parse the saved file and save it in VARS
const downloadText = await officeparser.parseOfficeAsync(filePath);
VARS.downloadText = downloadText;
As shown above, if you want to verify the filename of the downloaded file, you can access it like this: download.suggestedFilename();

CSV Files

const [download] = await Promise.all([
  page.waitForEvent('download'),
  // TODO: Modify the locator
  page.locator('<change this locator>').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
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.
5

Clean up

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