12 messages in com.canoo.lists.webtestRE: [Webtest] Grails like Groovy test...| From | Sent On | Attachments |
|---|---|---|
| Walton, Lynn | 26 Nov 2007 12:51 | |
| Walton, Lynn | 26 Nov 2007 14:54 | |
| Stephen de Vries | 26 Nov 2007 23:59 | |
| Dierk Koenig | 27 Nov 2007 01:05 | |
| Walton, Lynn | 27 Nov 2007 06:28 | |
| Marc Guillemot | 27 Nov 2007 07:24 | |
| Walton, Lynn | 27 Nov 2007 10:09 | |
| Marc Guillemot | 28 Nov 2007 02:33 | |
| Walton, Lynn | 28 Nov 2007 05:47 | |
| Marc Guillemot | 29 Nov 2007 11:24 | |
| Walton, Lynn | 29 Nov 2007 13:31 | |
| Marc Guillemot | 30 Nov 2007 00:47 |
| Subject: | RE: [Webtest] Grails like Groovy testing in non-grails project![]() |
|---|---|
| From: | Dierk Koenig (dier...@canoo.com) |
| Date: | 11/27/2007 01:05:00 AM |
| List: | com.canoo.lists.webtest |
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.




