[Webtest] How can I get storeXPath result in groovy

mascis mascis <juho.piirto@gmail.com>
Mon, 7 Nov 2011 06:21:57 -0800 (PST)


Hi,

I have similar problem as case 2 mentioned here. The thing is that I'm
running tests in NetBeans and I can't find a way to reach the value that is
stored in storeXPath-step. Line def groovyResult =
step.webtestProperties.fileName just gives some errors when I try to run
test.


dkoo761 wrote:
> 
> 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 <nocia.one@gmail.com> 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
>> WebTest@lists.canoo.com
>> http://lists.canoo.com/mailman/listinfo/webtest
>>
> 
> 

-- 
View this message in context: http://old.nabble.com/How-can-I-get-storeXPath-result-in-groovy-tp24668242p32788728.html
Sent from the WebTest mailing list archive at Nabble.com.