Thursday, April 30, 2009
WebTest Plugin 1.1.4.2 Released
It will download the latest snapshot by default when installed. If you would prefer the latest stable release (3.0) you can answer no when prompted.
Testing a JQuery-UI Drag and Drop using WebTest
The way that WebTest performs a drag and drop is as follows:
from.mouseDown() to.mouseOver() to.mouseUp()Note that there is no intermediate move events between mouse down on the thing you're dragging and mousing over the target element.
What this means is that you need to configure your Draggable to start dragging on mousedown without delay. You can do this by setting the distance and delay options to zero (delay is zero by default):
$('.block').draggable({distance:0});WebTest will now be able to click and drag it correctly. Unfortunately due to HtmlUnits 'renderless' behaviour you cannot specify exactly where you want to drop it so if you require precise targeting to properly test your application you're out of luck.
Saturday, April 4, 2009
Grails WebTest Plugin 1.1.4 Released
Another WebTest plugin release, this time with some new functionality!
Soenke Sothmann has contributed a nice patch to allow you to run custom suites of tests:
run-webtest -suite=MyTestSuite
Note that under windows you will need to quote the -suite argument due to an issue with Gant's argument parsing e.g. "-suite=MyTestSuite"
import grails.util.WebTest class MyTestSuite extends WebTest { static void main(args) { new MyTestSuite().runTests(args) } void suite() { new SomeTest1(ant:ant).suite() new SomeTest2(ant:ant).suite() // You could also load up certain tests based on naming conventions or annotations } }
In addition to this patch, there were some bug fixes relating to running webtests under Hudson and also around setting a custom port when starting up the server.
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.
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')