Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 6 Next »

There are many ways to test Web Applications with Groovy:

  • use Groovy to simplify the code required to drive a Java API browser simulator, e.g. HtmlUnit or HttpUnit
  • use Groovy to simplify the code required to drive a Java API for manually driving a real browser, e.g. IE or Firefox
  • use Groovy to interact with a higher-level testing library which uses one of the above two approaches, e.g. Watij (for the equivalent of Watir in the Ruby world) or WebTest (to open up the possibility of testing more than just web applications)

We examine a few approaches below.

Groovy and HtmlUnit

The following example tests the Google search engine using HtmlUnit:

Groovy and Watij

The following example tests the Google search engine using Watij:

You can use Watij from within groovysh or groovyconsole if you want to have an interactive (irb-like in ruby terms) experience.

Groovy and WebTest

The following example tests the Google search engine using WebTest:

The above fragment can be inserted into any Ant build script where we have defined the WebTest tasks.

The above example didn't use any Groovy but we could have just as easily used some Groovy for the last line if we didn't like the XPath expression, for example:

Alternatively, we could have written the whole test in Groovy, calling back out to Ant (and hence WebTest) as follows:

  • No labels