Monday, November 10, 2008

Grails WebTest Plugin 0.6 alpha

I've been working on committing some improvements to the Grails WebTest Plugin. You can download the alpha version here (I haven't yet released it to the plugin repository). I'd appreciate feedback from users with existing applications with non-trivial webtests regarding any regressions or upgrade issues they have. If all looks ok I will update the official repository version shortly.

Release Notes

  • setUp/tearDown at the method and class level

    • classSetUp() and classTearDown() are run as individual test cases. SetUp() and tearDown() are run as the first and last steps of each test case.

  • New superclass AutoWebTest

    • This new superclass will automatically run all methods starting with test. This saves you having to manually maintain the suite method unless you really want to for test order reasons.

    • AutoWebTest will also generate the test case name from the class and method name removing the need for repetitive webtest('blah'){...} code. The generated test name also makes it much easir to find the failing test from the generate reports.

    • MethodMissing code has been added so you can refactor a group of steps without having to wrap them in and ant.group closure.

    • You can now call config() as the first step in your test method to set WebTest options like host, port and ajax support

  • -nostart option allows you to runthe tests against a server that is already running. It should come after run-webtest on the command line

  • System parameters now passed through to WebTest. They need to be placed directly after grails on the command line e.g. grails -Dwt.headless=true run-webtest

    • -Dwt.headless=true to hide Swing monitor and stop browser launching

    • -Dserver.port=XXXX to get the tests to run against a server on a non-default port

  • The plugin has been updated with the latest WebTest release which includes an update of HtmlUnit to version 2.3

  • Application lib folder now on WebTest classpath. This avoids the need to duplicate/move libraries into webtest/home/lib

  • Custom steps

    • You can now extend com.canoo.webtest.steps.Step by placing groovy classes in webtest/tests/step. They will be automatically loaded at runtime and allow for easy testing of complicated scenarios such as JSON interfaces and email integration

      • The last project I worked on used these custom steps to start, check then stop an embedded Wiser SMTP server for testing email functionality.

Upgrade Instructions

delete plugins/webtest-0.x

svn delete webtest/home, commit.

This avoids svn issues as the install script deletes the folder and extracts the latest build over the top, removing the .svn directories

grails install-plugin grails-webtest-0.6.zip

You need to copy the zip file into the root folder of your project and run the command there.

Thursday, October 30, 2008

Open Source Developers Conference - Sydney Dec 2008

Myself and colleagues from Refactor will be attending the Open Source Developers Conference (OSDC) in Sydney from 2-5 Dec. It's a great conference to get in touch with developers who use and contribute to open source and find out what's on the horizon. I didn't get organised early enough to present any main sessions on Grails but am keen to do some lightening talks about it and also demo Balsamiq MockUps which I came across a few weeks ago. I think it's a great tool for agile BA's and product owners to really get their customers engaged. If you see me there, make sure you come over and say hi!

Wednesday, September 17, 2008

How to WebTest a site using an invalid SSL certificate

UPDATE: there is a option you can pass to the config step which should achieve the same thing: useInsecureSSL


A very short post regarding an issue I recently came across while testing an application I'm working on.

My application needs to interface with and existing PHP application that uses SSL. To acceptance test this functionality I am writing a WebTest that drives both applications to assert information is flowing correctly between them.

Unfortunately the test instance of the PHP application I have been given to use has a self-signed SSL certificate which causes WebTest to fail with a SSLHandshakeException.

To ignore the self signed certificate, add the following line to your test:

groovy('step.context.currentWebClientContext.webClient.useInsecureSSL = true')

Tuesday, August 26, 2008

Having trouble installing the Quartz plugin? Read on...

For those of you who don't follow the grails-users list, I thought I'd post a quick solution to solving an odd-looking compile error when installing the Quartz plugin into a Grails application that also uses the JSecurity plugin.
The compile error you will see is:
GrailsJobFactory.java:75: cannot find symbol
symbol  : constructor JobExecutionException(java.lang.String,java.lang.Exception)
location: class org.quartz.JobExecutionException
    throw new JobExecutionException(e.getMessage(), e);
It's caused by a library clash between the two plugins as JSecurity also ships with quartz.jar. Luckily (according to Les from the JSecurity project), JSecurity doesn't actually rely on that jar so you can delete it from plugins/jsecurity-x.x/lib which will solve the compile issue.

Monday, August 18, 2008

Grafton Hillclimb

I attended the Grafton Sporting Car Club's hillclimb on the weekend for the first time. It was loads of fun, and the first time I had my car out on a track. I managed to get under 60 seconds which was my goal for the day but hope to be a lot closer to the Evo's next time. I headed down with some top blokes from EvoOz and made a weekend of it. I can't wait to go back with improved suspension and tires, I just need to develop the business case in order to get it past the Minister for Finance. I think I'll try the improved safety angle... You can see how tight and technical the track is below.

View Larger Map
This is a shot taken by Nigel from Unique Images. Thanks a lot Nigel!
Photobucket - Video and Image Hosting

I feature at around 2:30 and 7:00 in the below video - great camera work/commentary by 'Pres' from EvoOz.

Tuesday, August 5, 2008

Jasper Reports Grails Plugin - sub-reports

Here's something that tripped me up when developing my first JasperReport containing a sub-report for use with the JasperReport grails plugin. In order for the sub-report to resolve correctly you need to add a parameter to your parent report called SUBREPORT_DIR. This is then set by the JR plugin, and makes everything work as expected. When specifying the sub-report location, set it to
$P{SUBREPORT_DIR}  + "mysubreport.jasper"
(assuming your subreport is in the same directory as the parent report and called mysubreport.jasper) Don't forget to give the parameter a default value of empty string so that it still works when previewing in iReport. You also need to remember that the plugin runs the compiled versions (*.jasper not *.jrxml) so you need to compile the reports with iReport before running the application.

Monday, August 4, 2008

Jasper Reports Grails Plugin Gotcha

Thought I'd blog this quickly: If you're using iReport to develop reports for use with the Jasper Reports grails plugin, make sure you download the version that matches the version of Jasper that the plugin uses (currently 2.0.5). Otherwise you get terribly unhelpful exceptions like:
java.lang.NullPointerException
 at net.sf.jasperreports.engine.JRPropertiesMap.readObject(JRPropertiesMap.java:185)