I'm glad to see that you are interested.
Groovy-style Webtests are regular Groovy code. That means you can use
alle the mechanics of a full-blown OO scripting language, particularly
inheritance and delegation.
Let's do a simple example that uses delegation.
Place a File Modules.groovy in one of your classpath roots.
Make it look like follows:
Modules.groovy
----------------------------------
class Modules {
static void login (ant, user, pw) {
ant.group(description: "logging in as $user"){
invoke url:'http://boondoogle.banana.com'
setInputField name:'user', value:user
setInputField name:'pw', value:pw
clickButton name:'login'
}
}
}
----------------------------------
This you can use from Groovy Webtests as seen in
http://webtest.canoo.com/webtest/manual/groovyTesting.html.
E.g. use it anywhere inside the 'steps' closure:
...
steps {
Modules.login(ant, 'scott', 'tiger')
verifyText text: 'logged in as scott'
...
}
...
This should work as shown above.
A few things can still be optimized.
- You can use
static import Modules
in your Groovy WebTest and simply refer to
login(ant, 'scott', 'tiger')
without the "Modules." qualifier.
- Mind the necessity to make the "ant" builder known to
the modules (highest level like "group" is sufficient).
There may be ways around that, but I haven't checked
(e.g. make Modules use static Closure properties instead
of static methods)
happy testing
Dierk
| > Well, I did find the grails.util.WebTest class .. Didn't
| realize it
| > was a plug-in. Would still love to see a sample on how to make a
| > groovy web test use modules.
| > Thanks
|
| I'll second that! I currently have a project where mixing
| ant tests and groovy steps is becoming quite messy.
| If the whole project were written in grails style webtests it
| would solve a lot of issues.
| Lynn, I'd be interested to hear about your progress in this.
_______________________________________________
WebTest mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/webtest