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 azero-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 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 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 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.

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 ;)

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:

Open a console, go to the folder you unziped the application and type:

mvn install eclipse:eclipse

mvn webtest:clean webtest:test webtest:report

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

Acknowledgments

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

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