Percy PDF testing
Learn how to visually test and compare PDF files across multiple releases.
This percy-pdf code repository provides an approach to compare Portable Document Format (PDF) files using Percy for visual testing requirements across multiple application releases.
Get started
Step 1: Organize your PDF files
Copy the PDF files that you want to visually compare into the projects folder within this repository. Ensure that these PDF documents are grouped based on <project-name> and then <release-version>. A typical directory structure looks like this:
projects/
insurance-policy-docs/ # <-- your-project-name-folder
golden-copy/ # <-- your-baseline-release-folder
pdf-file-1.pdf
pdf-file-2.pdf
pdf-file-3.pdf
release-v2/ # <-- your-another-release-folder
pdf-file-1.pdf
pdf-file-2.pdf
pdf-file-3.pdf
release-v3/ # <-- your-another-release-folder
pdf-file-1.pdf
pdf-file-2.pdf
pdf-file-3.pdf
This repository includes a sample project folder (insurance-policy-docs) with different folders such as golden-copy and release-v2 indicating different versions of the PDF documents. You can create as many new folders as you need for each new release of the PDF document.
Step 2: Create a PDF run info config file
Create a PDF run info config file within the ./configs folder. Sample config files are available at ./configs.
Step 3: Set up a Percy account
Create an account on Percy and create a new Percy Web project. Note the project-specific PERCY_TOKEN, as you will need it when triggering the project builds.
Step 4: Clone the repository
Clone this repository and navigate to the project folder:
git clone git@github.com:BrowserStackCE/percy-pdf.git
cd percy-pdf
Step 5: Install Node.js
Use the latest LTS version of Node.js. You can install it from here.
Step 6: Install dependencies
Install the repository dependencies:
npm install
Step 7: Set the environment variable
Export the environment variable PERCY_TOKEN, obtained in step 3, using the command below.
For *nix-based and Mac machines:
export PERCY_TOKEN=<percy-project-token>
For Windows:
set PERCY_TOKEN=<percy-project-token>
Step 8: Trigger the run
Trigger the run using the following command:
npm test -- <run-info-config-file-path.yml> <Optional PORT Param. Default 8080>
Examples:
npm test -- configs/getting-started-scenarios/01_pdf-docs-run-info-baseline.yml
npm test -- configs/getting-started-scenarios/01_pdf-docs-run-info-release2.yml
If you want to provide a dynamic port value for the web server, provide the PORT as the second argument to the command:
npm test -- <run-info-config-file-path.yml> <Optional PORT Param. Default 8080>
Examples:
npm test -- configs/getting-started-scenarios/01_pdf-docs-run-info-baseline.yml 8081
npm test -- configs/getting-started-scenarios/01_pdf-docs-run-info-release2.yml 8081
Step 9: Trigger advanced scenarios
You can trigger the advanced scenario in a similar fashion once you have reviewed the advanced PDF run config file flags (and have relevant use cases), as documented in the PDF run config file section as follows:
npm test -- <run-info-config-file-path.yml>
Examples:
npm test -- configs/advanced-scenarios/01_pdf-docs-run-info-baseline.yml
npm test -- configs/advanced-scenarios/01_pdf-docs-run-info-release2.yml
PDF run config file
The PDF Run Info file provides several flags that specify information about the PDF documents for visual comparison. This section details all the flags.
Mandatory flags
These flags are required in every PDF run config file to define the basic comparison parameters.
| Flag | Description | Example |
|---|---|---|
runMode |
The run mode, whether creating a new baseline or comparing existing baseline with new release. Based on the requirement, this value can be create-baseline or compare-release-with-baseline. |
create-baseline or compare-release-with-baseline
|
projectFolders |
An array of folders under the projects folder in the root directory. |
[insurance-policy-docs, test-docs] |
baselineDir |
The directory under the project folder that contains the baseline PDF documents. | golden-copy |
releaseDir |
The directory under the project folder that contains the new release PDF documents. This flag is optional when creating a new baseline Percy build, but becomes mandatory for a comparison build between baseline and new release. | release-v2 |
Optional flags
These flags provide additional customization options for PDF comparison workflows.
| Flag | Description | Sub-flags | Default | Example |
|---|---|---|---|---|
includeDocs |
An array of PDF documents under the project folder that should be included for comparison. If this tag is not provided, all PDF documents under the project folder are chosen by default; otherwise, only the specified documents are chosen. |
project: The project folder for the documentdoc: The document name with the .pdf extension |
All documents included |
includeDocs: - project: insurance-policy-docs doc: pdf-file-1.pdf
|
excludeDocs |
An array of PDF documents under the project folder that should be excluded from comparison. If this tag is not provided, no PDF documents under the project folder are excluded by default; otherwise, only the specified documents are excluded. |
project: The project folder for the documentdoc: The document name with the .pdf extension |
No documents excluded |
excludeDocs: - project: insurance-policy-docs doc: pdf-file-3.pdf
|
specialDocConfigs |
This flag provides further customization to include/exclude certain pages of any PDF document. The specific document is identified using the project and doc flags, and further flags includePages/excludePages are provided to include or exclude pages in the PDF document during baselining or comparison. |
project: The project folderdoc: The document nameincludePages: Pages to includeexcludePages: Pages to exclude |
None |
specialDocConfigs: - project: insurance-policy-docs doc: pdf-file-1.pdf excludePages: [2, 3]
|
createNewBuildPerDoc |
For any PDF Run Config file, by default, a single build is created that clubs all PDF documents across user projects in a single Percy build. However, if you want to create a new Percy build per PDF document, then createNewBuildPerDoc can be optionally set to true. |
None | false |
createNewBuildPerDoc: true |
percyConfigs.waitForTimeout |
Percy snapshot internal configuration that can be passed by the user through the PDF Run Info Config file. It specifies an amount of time to wait before capturing a snapshot in milliseconds. | None | None |
percyConfigs: waitForTimeout: 200
|
Things to know
-
PDF file matching: The script identifies PDF files to compare based on matching file names across different release directories. For example,
insurance-policy-docs/release-v2/pdf-file-1.pdfcompares againstinsurance-policy-docs/golden-copy/pdf-file-1.pdf. -
Page exclusion limitation: The
excludePagesflag within the PDF Docs Run Info Config file does not allow excluding PDF Page 1 and the second-to-last page.
Need more support? Contact BrowserStack.
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
We're sorry to hear that. Please share your feedback so we can do better
Contact our Support team for immediate help while we work on improving our docs.
We're continuously improving our docs. We'd love to know what you liked
Thank you for your valuable feedback!