Skip to main content

Testing PDF files with Canoo Webtest and Maven2

Posted by felipegaucho on November 18, 2009 at 6:14 AM PST

This week I received one of that lovely and tricky tasks: to
learn Canoo
, 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
test. 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 href="">very
    well documented webtest distribution. There is only one gotcha: the ant
    task depends on a library which you need to copy locally somewhere.

  • Groovy + GMaven: there is an entry in the href="">Marc Guillemot'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 href="">webtest-maven-plugin
    is a pure Maven plugin that enables 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 of 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>
href=""> border="0" src="" />

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 days translating the ant samples to maven I
finally got the below configuration. I
believe other enhacements can be done in order to make the whole
solution more elegant, but so far it does the job and I have my
presentation ready for the managers ;)

<project name="Canoo Webtest Sample" basedir="." default="all">
<target name="all">
<ant antfile="checkPageCount.xml" /> <!-- 1 test per PDF page -->
<ant antfile="checkWatermark.xml" />

A test example, a simple test to check if the PDF contains a watermark with the word

<project default="test">
<property name="pdf.file" value="${basedir}/foo.pdf" />

<taskdef resource="" />
<target name="test">
<webtest name="watermark">
<config protocol="file" summary="${summary}" saveresponse="false"
resultpath="${resultpath}" resultfile="${resultfile}"
haltonfailure="${haltonfailure}" haltonerror="${haltonerror}"
autorefresh="${autorefresh}" />

<invoke description="get PDF document" url="${pdf.file}" />
<pdfVerifyText description="Check watermark"
text="" startPage="1" endPage="1" />

Download the complete example

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. href="">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 href="">Webtest
mailing lists, with special thanks to Christoph Lipp, nodje and
Marc Guillemot. My task is not yet finished but the support of those
community members was fundamental to my first success using Canoo

Blog UPDATE: Canoo published a set of new samples, available here. Take the latest version, unzip and look in the folder src/test, specially the example it8 about PDF testing.

Related Topics >>