Zeenyx Academy

PDF Comparison

Print Friendly, PDF & Email

We’ve received several requests for assistance on how to create a test that compares the contents of a PDF file generated by the target application to a baseline. Because PDFs often contain some lines that have variable information, the ability to mask out lines from the comparison is imperative. It turns out to be a fairly easy exercise and the result is a step that can be reused to compare any PDF to its baseline. Here is an image that displays the solution. The description follows below:

 

The step, ‘ComparePdfFileToTemplate’ takes four parameters:

1. PDF_FileName – the name of the PDF file
2. PageAppObjectName – the AppObject Name of the PDF Page.
3. bCapture – a flag that indicates whether to capture a new baseline
4. SkipLines – a list of the line numbers to skip when comparing

The PDF file is loaded into a buffer. Then the name of the pdf file is stripped from the path.

If the user indicates that a new capture is required, the step gets all the text from the PDF file and writes it to a new baseline file in the ‘Run\Project\Other’ folder. The baseline file name is comprised of the original file name plus the AppObject page name to accommodate multiple page PDFs.

If bCapture is false, the step writes out the baseline to the results file, assigns the actual contents of the target PDF file to a list of string and then performs a line by line comparison between the expected results store in the baseline and the actual results, skipping the lines that are listed in the SkipLines list.

As you can see in the image above, the step is quite simple.

Here is the data table used to provide the parameter values to the step.

 

Each of the two pages that were compared in this example had two lines that needed to be skipped because they contained data generated at runtime that would differ from run to run. The variable data was handled by a separate step.

As noted above, the baselines are generated in the Run folder when ‘bCompare’ is set to true. The user needs to copy the baselines to the ‘Other’ folder in the AscentialTest Project path:

Finally the files must be added to the ‘Other Files’ section of the Project Explorer so that they will be available to the executing test at runtime:

If you would like to receive a copy of ‘ComparePdfFileToTemplate’, send a request and we will be happy to provide it.

 

Share the Post:

Related Content

Instructional Content, Thought Leadership

A Thousand G2 Reviews Later: Software Testing Tools Are Too Expensive

Instructional Content, Thought Leadership

Build Tests, Not Frameworks

Instructional Content

AscentialTest Error Tracking and Debugging

Instructional Content

Self-Guided PowerBuilder Tutorial

Get Started For Free: 30 Day Trial

Click here to download the Host ID generator. The download package includes full instructions. Please send us your details below to speed the process along.

Our Distribution and Consulting Partners

Appeon

Cigniti

Loop Software

Marlabs

Matryxsoft Tech

Novalys

OCS Consulting

Loading...

What We Are Up To Next

TFS/Azure Integration

Check our new Azure extension for executing AscentialTest command lines in the Azure Marketplace.

We look forward to offering additional integration with Microsoft’s Team Foundation Server and Azure through defect tracking and version control soon.

Omnis Studio

Automated testing support for OMNIS Studio is coming soon. All OMNIS elements will be supported including complex grids, list boxes, tables and tree views.

Custom Objects

Add automated testing support easily for your custom application elements by responding to simple test API messages with json strings. This feature will open up the possibility of testing any GUI element and  will be offered free of charge.

Test Debugger

Set breakpoints in your automated tests, view global and local variables and execute statements to make it easier to debug tests running on any of our supported platforms.

Get a Competitive Quote

Thank you for submitting your inquiry!

We will get back to you ASAP.  We aim to respond to all inquiries within 24 hours.