Hi Nocia,

When you store an XPath value in a WebTest property, you can't directly
access it as a Groovy variable in your test since WebTest properties are not
shared with Groovy (yet).

Depending on what you need to do with the property, there are 2 approaches:

1) If all you want to do is use the property in another test step, then you
can simply use this syntax: #{insert-property-name}

Here's an example: invoke "somecontroller/someaction/#{someResult}"

2) If you actually need to use the property in some Groovy expression then
you can create a Groovy step, retrieve the property from within the Groovy
step, store it as a Groovy variable and use it there.

Here's an example of how to do that:

        storeXPath xpath:'//div[2]', property:'someResult'
        groovy """
            def groovyResult = step.webtestProperties.someResult

            // do something in Groovy with groovyResult....

            // now if you need to, put the modified Groovy variable back
into WebTest properties so you can access it in your subsequent test steps.
            props.putAt("someResult",groovyResult)
        """

Good luck,
Dave



On Sun, Jul 26, 2009 at 9:19 AM, Nocia <[email protected]> wrote:

> Hi all,
>
> I'm trying to use storeXPath in groovy.
>
> My code looks like that :
>
>    void tests(){
>
>        webtest "test", {
>
>            invoke url: "http://...";, description: "Go to test website"
>            storeXPath xpath:'//div[2]', property:'result'
>            println("#result")
>            println("$result")
>
>         }
>    }
>
> But I get :
>
> #result
> null
>
> So how can I get the result?
>
>
> _______________________________________________
> WebTest mailing list
> [email protected]
> http://lists.canoo.com/mailman/listinfo/webtest
>

Reply via email to