user-icon Pascal Moll
22. August 2014
timer-icon 3 min

Testing PDF documents using Firefox and testIT WebTester

Let´s imagine for a second your boss has a new assignment for you. He wants you to automatically test the structure of generated PDF documents. Sounds like a pain in the lower body region? Not entirely. This blog post will show you a basic concept and an example of how to test structure and content of PDFs using Firefox and testIT WebTester.

Concept

For quite a while the Firefox supports HTML 5. So if you open a PDF document in the Firefox Browser, it transforms the document into an HTML 5 Canvas element. It may look like this:

testIT PDF Tester - canvas element with Firebug in Firefox

testIT PDF Tester – example of PDF document in Firefox

As you can see, the whole document has been translated into an HTML DOM structure.

Everything starts with the “viewerContainer” element, followed by the viewer and after that, it continues with the pages.


Each page has its own wrapper with properties and their own elements.


Each element has also properties for example width and height.

To conclude the conceptual part, you have to find the elements you want to check and test their properties, or you go ahead and test the whole document page by page.

Exactly those two usecases are part of the PDF support addon to our testIT WebTester.

1) Compare two PDF documents with testIT

To compare two documents and test them, we have to start with an entry page. The WebTester reads structure and content of this page and compares it.

Let´s test if page 1 of both documents is equal. To do so we would write a test like the following:


The following happens:

  1. Open browsers and load PDFs.
  2. Advice the browser to go to page 1 and set zoom level to 100%.
  3. Activate comparison feature.
  4. Set checkpoint and execute.
  5. Get test results.

If the documents would not be equal, checkpoint result would contain the exact reason why.

2) Use checkpoints to test specific attributes with testIT

Using the checkpoint technique to test several lines works like the following:

  1. Open browsers and load PDF.
  2. Set zoom level to 100%.
  3. Navigate to the page of the first checkpoint.
  4. Search for the specific line containing “Invoice”.
  5. Set checkpoint and execute.
  6. Get test results.

Now in this example we check if the position of the text “Invoice” is correct, if the font family is monospace and if the font size is 26f /- 1.

Keep in mind, you can use as much checkpoints as needed.

Video of a test

Example of testing PDF documents using testIT WebTester

Download pdf addon for webtester

You can either download the WebTester distribution from our FTP server or you can use our NovaTec public maven repository:

Dependency and Repository

Conclusion

The testIT WebTester is extremely usefull for userinterface based testing and because of the fact that it can handle HTML elements so well, the PDFTester addon is a great way to test PDF documents.

Feel free to check it out yourself.

Please let me know if you have any questions or comments.

Comment article