Over a million developers have joined DZone.

Testing PDF files with Canoo Webtest and Maven2

DZone's Guide to

Testing PDF files with Canoo Webtest and Maven2

· Java Zone ·
Free Resource

Atomist automates your software deliver experience. It's how modern teams deliver modern software.

This week I received one of that lovely and tricky tasks: to learn Canoo webtest, test it and prove its usefulness to the project in three days - convincing the managers that it should be part of the project. The goal of the project is to produce a finance report with ~200 pages and that report should be validated through a zero-errors acceptance tests. Several tools were considered, including Selenium and others, but Canoo was choosen due to its PDF test features.

Testing PDF documents with Maven & Canoo webtest

Canoo webtest can be used in three different ways:

  • Ant task: this is the original and very well documented webtest distribution. There is only one gotcha: the ant task depends on a library that you need to copy locally somwhere.
  • Groovy + GMaven: there is an entry in the Gillemot's blog explaining how you can code your webtest in Groovy instead of using ANT. It is a perfect choice if you are already using Groovy but in my case an extra language would cost unnecessary explanations in the technical meeting :)
  • WebTest Maven2 Plugin: the webtest-maven-plugin is a pure Maven plugin that enable your application to test the generated PDF files without any dependencies to local artifacts and without the need to add Groovy to the technology set of your project. That's the way I was looking for and that's my prime choice.

After a first hour of euphoria the things started to get muddy with the configuration of the maven plugin. I am not sure if due to the tight deadline or just because the scarce documentation on the web, but nevertheless after joining the mailing list of Canoo I started to find my way.

Maven configuration

<name>WebTest dependencies</name>

The webtest configuration

The configuration of the test was a bit complicated because I couldn't find a runnable example on the web (the main motivation to this blog entry). After two day translating the ant samples to maven I finally got the below configuration. It works but it is yet not perfect, because I am not sure about all its details and not sure how to make it modular. I will update this entry as soon I figure out how to make it modular, if you know that already please give me your feedback. I believe other enhacements can be done in order to make the whole solution more elegant, but so far it do the job and I have my presentation ready for the managers ;)

<target name="all">
<webtest name="Test">
<config protocol="file" haltonerror="false" haltonfailure="false" summary="true" saveresponse="true" resultpath="../../../target/webtest/webtest-results" />
<invoke description="get PDF document" url="${basedir}/foo.pdf" />
<pdfVerifyPageCount count="1" />
<pdfVerifyText description="Investment Proposal" text="Canoo webtest line #1" startPage="1" endPage="1" />

Download the complete example

Here you can download the complete example, it only requires Maven 2 and should work out of the box. any problems trying that, please let me know. In order to run the example, please follow the below steps:

  1. Download and unzip the sample application.
  2. Open a console, go to the folder you unziped the application and type:
  3. mvn install eclipse:eclipse
  4. mvn webtest:clean webtest:test webtest:report

Done, you will find the report in the file .\myWebTestApp\target\site\webtest\index.html


I received a helpful support from the Webtest mailing lists, with special thanks to Christoph Lipp, nodje and Marc Guillemot. My task is not yet finished but the support of these community members was fundamental to my first success using Canoo webtest.



Get the open source Atomist Software Delivery Machine and start automating your delivery right there on your own laptop, today!


Published at DZone with permission of

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}