Canoo Webtest WebTest Canoo

Groovy Testing

Groovy is a scripting language that is executed as Java Byte Code. Groovy Home

This allows a Mix & Match between Groovy and Java Code.

Groovy comes with an AntBuilder that allows execution of Ant scripts from usual Groovy code. This capability allows executing WebTests, since WebTests are usual Ant tasks.

By executing WebTest from a Groovy script, you can fully leverage both the variety of WebTest steps and the sophisticated language means of Groovy for structuring your tests.

Sample use

This example fetches a page and verifies that it contains the numbers 1 through 10.

test.groovy
def ant = new AntBuilder()

def webtest_home = System.properties.'webtest.home'

ant.taskdef(resource:'webtest.taskdef'){
    classpath(){
           pathelement(location:"$webtest_home/lib")
           fileset(dir:"$webtest_home/lib", includes:"**/*.jar")
    }
}


def config_map = [:]
['protocol','host','port','basepath','resultfile',
'resultpath', 'saveresponse','defaultpropertytype'].each{
    config_map[it] = System.properties['webtest.'+it]
}

ant.testSpec(name:'groovy: Test Groovy Scripting at creation time'){
    config(config_map)
    steps(){
        invoke(url:'linkpage.html')
        for (i in 1..10){
            verifyText(description:"verify number ${i} is on pages", text:"${i}")
        }
    }
}

Like in ANT, there is a two-phase approach for TaskContainers like 'testSpec'.

first
steps are constructed and stored (creation time)
second
steps are executed (runtime)

Start with groovy -Dwebtest.home=your_webtest_home test.groovy

More examples

Please find more examples of how to use Canoo WebTest through Groovy under Grails.

news

Latest build: R_1823
Posted: 20-Feb-2013 12:26

WebTest 3.0 released, featuring upgrades to Java 5, Groovy 1.6, and HtmlUnit 2.4.
The release includes support for maven integration, IDE-integration like for unit tests, capturing of background JavaScript errors, new steps for mouseOver and mouseOut events, better parallel execution of tests and - as usual - lots of handling improvements.
Posted: 5 March 2009

WebTest @ JavaOne
Dierk König presented "Functional testing of web applications: scaling with Java" on Wed May 7, 13:30 at JavaOne 2008 in the Tools and Scripting Languages track.
Posted: 8 May 2008

New WebTest screencast available:
Data Driven WebTest
Posted: 13 November 2007

First WebTest screencast available:
Creating a first Webtest Project

Extend WebTest with Groovy! Groovy in Action is available in every good bookstore.
Groovy in Action
Posted: 29 January 2007