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.