Hi Jean Sebastien,
  I'm new too with Webtest, and I use it with groovy as you do - I guess.
You should check this thread :
http://lists.canoo.com/pipermail/webtest/2009q2/012144.html
It gave me a lot of clues to begin with Groovy.

I think the reason of your problem is detailed in the previous link.
However, the idea is that when you
use / share dynamic variables, you should not use the 'main' groovy context.
Assuming you need
to share a property between Webtest context and a groovy one, declare it as
_dynamic_ (step is dynamic for instance ;-) ):

ant.testSpec(name:"Yo"){
            config(config_map){
                option(name:"ThrowExceptionOnScriptError",value:"false")
            }
            steps(){
// ...
// Here, I'm in my Groovy class but in an AntBuilder steps "context"

storeProperty(name:"counter", value:"000",
                        propertyType:"dynamic")
// ...
            }

then use your variable 'counter' in a groovy step. Not in the "main" groovy
context, but like this :

             steps(){
// Here, I'm in my Groovy class but in an AntBuilder steps "context"

storeProperty(name:"counter", value:"000",
                        propertyType:"dynamic")

groovy (description:"Counter for filename", '''

                        //Here, I'm in a kind of "groovy Webtest context"

                        def props = step.webtestProperties
                        def intCounter = props.counter
                        intCounter =
String.valueOf((Integer.parseInt(intCounter))+1)
                        props.putAt("counter", intCounter)
                        ''')

//Re-use your property with a sharp :

clickLink(xpath:"//div[4]/p[#{counter}]/a")
            }

You seem to focus on getting the Ant 'step' context, but I thought you could
be interested in handling groovy / ant variables as well.

NB: As Marc explained me (
http://lists.canoo.com/pipermail/webtest/2010q3/013274.html), you should
rather use a WebTestBuilder context rather than an AntBuilder one, to avoid
the use of triple quotes in the groovy step.

Regards,
Guillaume

2010/7/12 <[email protected]>

>
> Hi,
>
> I have been using webtest for a few weeks now.  The more I use it, the more
> I like it.  Now as I explore new features, I have bumped in a problem I
> can't seem to resolve.
>
> I am writing my tests in groovy, and store each test classes under my
> project's /tests directory.  Every test executes as advertised, except I
> can't get a handle on the AntBuilder/WebTestBuilder.  I read that within the
> step I could have called directly ant.step, or getAnt().step, both of them
> returned were null.
>
> Am I doing something wrong?  Being unable to access the ant/step prevents
> me to use the data driven feature, plus I can't retrieve stored variables in
> previous steps.
>
> Thanks for all the help you can provide,
>
> Regards,
>
> JS.

Reply via email to