How to test PDF files
Introduction
Endtest provides several ways to work with PDF files during your automated tests, from extracting metadata, to analyzing content using AI, to converting PDFs into HTML for direct interaction.
Testing PDF metadata
After your test downloads a PDF file, you can extract metadata using the Set Variable action with these methods:
- Extract Name of Most Recent Downloaded File
- Extract Size of Most Recent Downloaded File
- Extract MIME Type of Most Recent Downloaded File
- Link to Most Recent Downloaded File
You can then use the resulting variables in later steps, such as: Add Assertion → Variable Assertion.
Opening the PDF in the browser
If your test downloads a PDF file, you can open it in the browser by inserting the variable from Set Variable → Link to Most Recent Downloaded File into a Go to URL step.
To open the PDF in a separate browser tab, use:
- Miscellaneous → Open new tab
Place this step before the Go to URL step so the PDF opens in the newly created tab.
After opening it in a new tab, you can navigate between tabs using:
- Miscellaneous → Switch to next tab
- Miscellaneous → Switch to previous tab
Because a PDF is not composed of HTML elements, its internal content cannot be clicked or located directly. To interact with individual elements, convert the PDF into HTML (see below).
Testing PDF content
There are multiple approaches to validate PDF content, depending on your needs.
1. Extract Invoice Data from PDF using AI
You can extract structured invoice information using the extractInvoiceDataFromPDF action from the Endtest Utilities API.
This action uses AI with Deep Learning OCR and Document Understanding Models to detect fields such as:
- invoice number
- invoice date
- vendor name
- subtotal, tax, total
- line items
Endtest converts the output into a simple, predictable JSON format.
You can extract values from this JSON using:
Miscellaneous → Utilities → Extract Value from JSON
Note:
extractInvoiceDataFromPDFdoes not require opening the PDF in a browser.Note:
extractInvoiceDataFromPDFprocesses only the first page of a PDF. If your invoice spans multiple pages and you need to extract data from each of them, first split the PDF using theextractPageFromPDFaction, then runextractInvoiceDataFromPDFon each extracted page separately.
2. Convert the PDF into an HTML file
You can convert any PDF into an HTML file using the convertPDFtoHTML action from the Endtest Utilities API.
This makes the PDF content interactive, allowing you to use standard Endtest actions such as:
- Scroll
- Click
- Snipping Tool
- Miscellaneous → Generate Full Page Screenshot
- and others
If the PDF contains links or buttons, you can click them using a Text Inside or Link Text locator (since the HTML elements might not have attributes).
Note:
convertPDFtoHTMLdoes not require opening the PDF in a browser.
3. Computer Vision
You can validate the visual appearance of a PDF (or its HTML version) using:
Add Assertion → Page Matches Screenshot
This compares the rendered content with a baseline screenshot from a previous test execution.
Note: Using Computer Vision requires opening the PDF (or the generated HTML) in the browser so Endtest can capture and compare its visual output.
