[Webtest] Accessing responses in webtest and groovy

Torsten Feig webtest@lists.canoo.com
Tue, 16 May 2006 15:51:27 +0200


I'm evaluating Webtest+Groovy as a test tool for our company and got stuck 
at 2 points:
1) How can I access a response that is the result of a javascript executed 
on loading a page? As I have experienced, the following steps refer to the 
initial page but ignore the afterwards loaded document, which is an excel 
sheet that is opend in a new unnamed window.
2) For the many groovy-steps I needed in my Webtest-XML I also tried the 
option to write a groovy script that calls webtest tasks, as suggested in 
the "Groovy Testing" article 
(http://webtest.canoo.com/webtest/manual/groovyTesting.html). The problem is 
that this example doesn't mention how to retrieve the response/document of 
the previously executed step for direct access in Groovy. I tried several 
imaginable ways but all failed, the main problem being that adding steps 
with the AntBuilder doesn't execute them right away, but the Groovy script 
between these step additions is executed in the first pass, resulting in a 
null value returned by the context-Property of a step, like this:
steps() {
    def context = invoke('someUrl').context
    def table = 
context.currentResponse.documentElement.getHtmlElementById('someTable') //-> 
NPE because context is null at this point

I would very much welcome any ideas on these issues.

PS: Currently the codehaus-website is unreachable (at least for me), so I 
cannot refer to the Grails-examples that have been mentioned in other 
postings which could be helpful for my second question.