[Webtest] accesing StepResults in a Groovy WebTest

Florent Blondeau Florent Blondeau <fblondeau@pingwy.com>
Tue, 27 Nov 2007 12:10:54 +0100


This is a multi-part message in MIME format.
--------------090400050303090408030504
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 8bit

Hi Stefan,

What I showed was about properties set while processing steps.
For example, a value stored by
storeXPath(xpath:'//xpath', property:"xpathprop")
will appear with

task.dynamicProperties.each {key, value -> println key + " : " +
value}

as
xpathprop : xpathvalue

But I see that's not what interests you. So I took a big breath and I 
dived deep into the sources.
I discovered wonderful things, and I'm very happy that things have been 
done !!
Thanks to you

In order to access the results, you can proceed by calling the static 
method
def context = WebtestTask.getThreadContext()
and then
context.getCurrentResponse().asXml() for example (the important thing is 
to have CurrentResponse)

I didn't manage to do that !!!!!!!!!!!!!!!!!!!!!!!!!!! Because of 
dependencies problem between my Eclipse projects,
I didn't manage to import WebtestTask.

So I found a different method :

      def webtest

      ant.getAntProject().taskFinished = {buildEvent -> def task = 
buildEvent.task
                                                          println "Task 
finished ............ $task.taskType"
                                                          if 
(task.taskType == 'invoke'){
                                                              println 
"**********************************************************************************"
                                                              def page = 
webtest.getStepSequence().getContext().getCurrentResponse().asXml()
                                                              println page
                                                              println 
"**********************************************************************************"
                                                          }
                                           }

      ant.getAntProject().taskStarted = { buildEvent ->  def task = 
buildEvent.task
                                                           println "Task 
started ............ $task.taskType"
                                                           if 
(task.taskType == 'testSpec'){
                                                              webtest = task
                                                             
                                                              }
                                          }
It's very very very bad, I know...

If you don't need to "catch" this outside of the steps execution, it's 
pretty simpler :
you just need to have a groovy() step with a
def response = step.getContext().getCurrentResponse()
(or def response = step.context.currentResponse in a "groovier" way)

I think that most of the cases can be handled with a groovy() step... 
but it could be precious to catch response out of the execute() method
of the steps

Hope that helps

florent

Stefan Majer a écrit :
> Hi Florent,
>
> thanks for this, but 
>
> task.dynamicProperties.each {key, value -> println key + " : " +
> value}  
>
> does not give me any entries..
> So do you have an idea how to get to all the information's stored during
> the steps ?
>
> greetings 
>
> Stefan Majer
>
> On Mon, 2007-11-26 at 14:36 +0100, Florent Blondeau wrote:
>   
>> Hi,
>>
>> If I understand what you want, I can share a workaround I found when 
>> using steps. Actually, I have some groovy code that call
>> webtest steps with ant, with a <groovy> step with some groovy code 
>> (That's a bit weird, but it
>> was to test if this kind of thing works).  I wanted to share variables 
>> between my groovy code and
>> the groovy step, for example.
>>
>> you can do something like this before calling your ant.testSpec :
>>
>>       ant.getAntProject().taskFinished = {buildEvent -> def task = 
>> buildEvent.task
>>                                                           println "Task 
>> finished ............ $task.taskType"
>>                                                           if 
>> (task.taskType == 'testSpec'){
>>                                                                          
>> //that's fired when testSpec is finished, but you can
>>                                                                         
>> // do that for all your steps
>>                                                        
>>                                                                        
>> //an example of what you can do :
>>                                                                        
>> // you get all the properties defined in your tests
>>                                                                        
>> // useful when you want to feed a database, for instance
>>                                                                        
>> task.dynamicProperties.each {key, value -> println key + " : " + value}  
>>                           
>>                                                           }
>>                                            }
>>
>>       ant.getAntProject().taskStarted = { buildEvent ->  def task = 
>> buildEvent.task
>>                                                            println "Task 
>> started ............ $task.taskType" }     
>>
>> If you want to get the results, I saw there was a method called 
>> getResultBuilderListener() to get the listener which
>> contains the results. I didn't try but it could be a way to get that 
>> with task.builderListener.previousResponse or something
>> like that
>>
>> It's really possible that a much simpler way exists, but I'm pretty new 
>> to webtest and I don't know all the possibilities. So
>> i don't claim that i hold the only truth ;-)
>>
>> hope that helps
>>
>> florent
>>
>>
>> Stefan Majer a écrit :
>>     
>>> Hi,
>>>
>>> i want to access the stepResults eg. duration etc. in a simple groovy
>>> webtest script like this:
>>>
>>> ant.testSpec(name:'simple Groovy Webtest'){
>>>     config(config_map)
>>>     steps(){
>>>         invoke(url:'linkpage.html')
>>>         verifyText(description:"Index", text:"index")
>>>         }
>>>     }
>>> }
>>>
>>> Is it possible to get these for every called step ?
>>>
>>> greetings 
>>>
>>> Stefan Majer
>>>
>>> _______________________________________________
>>> WebTest mailing list
>>> WebTest@lists.canoo.com
>>> http://lists.canoo.com/mailman/listinfo/webtest
>>>   
>>>       
>>     
>
> _______________________________________________
> WebTest mailing list
> WebTest@lists.canoo.com
> http://lists.canoo.com/mailman/listinfo/webtest
>   


-- 
Pingwy
27, rue des arènes
49100 Angers


--------------090400050303090408030504
Content-Type: text/html; charset=ISO-8859-15
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-15"
 http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Stefan,<br>
<br>
What I showed was about properties set while processing steps.<br>
For example, a value stored by <br>
storeXPath(xpath:'//xpath', property:"xpathprop")<br>
will appear with <br>
<pre wrap="">task.dynamicProperties.each {key, value -&gt; println key + " : " +
value}</pre>
as<br>
xpathprop : xpathvalue<br>
<br>
But I see that's not what interests you. So I took a big breath and I
dived deep into the sources.<br>
I discovered wonderful things, and I'm very happy that things have been
done !!<br>
Thanks to you<br>
<br>
In order to access the results, you can proceed by calling the static
method <br>
def context = WebtestTask.getThreadContext()<br>
and then<br>
context.getCurrentResponse().asXml() for example (the important thing
is to have CurrentResponse)<br>
<br>
I didn't manage to do that !!!!!!!!!!!!!!!!!!!!!!!!!!! Because of
dependencies problem between my Eclipse projects, <br>
I didn't manage to import WebtestTask.<br>
<br>
So I found a different method :<br>
<br>
      def webtest<br>
<br>
      ant.getAntProject().taskFinished = {buildEvent -&gt; def task =
buildEvent.task<br>
                                                          println "Task
finished ............ $task.taskType"<br>
                                                          if
(task.taskType == 'invoke'){<br>
                                                              println
"**********************************************************************************"<br>
                                                              def page
= webtest.getStepSequence().getContext().getCurrentResponse().asXml()<br>
                                                              println
page<br>
                                                              println
"**********************************************************************************"<br>
                                                          }<br>
                                           }<br>
<br>
      ant.getAntProject().taskStarted = { buildEvent -&gt;  def task =
buildEvent.task<br>
                                                           println
"Task started ............ $task.taskType"<br>
                                                           if
(task.taskType == 'testSpec'){<br>
                                                              webtest =
task<br>
                                                              <br>
                                                              } <br>
                                          }<br>
It's very very very bad, I know...<br>
<br>
If you don't need to "catch" this outside of the steps execution, it's
pretty simpler :<br>
you just need to have a groovy() step with a <br>
def response = step.getContext().getCurrentResponse()<br>
(or def response = step.context.currentResponse in a "groovier" way)<br>
<br>
I think that most of the cases can be handled with a groovy() step...
but it could be precious to catch response out of the execute() method <br>
of the steps<br>
<br>
Hope that helps<br>
<br>
florent<br>
<br>
Stefan Majer a écrit :
<blockquote cite="mid:1196103715.6496.3.camel@dom2" type="cite">
  <pre wrap="">Hi Florent,

thanks for this, but 

task.dynamicProperties.each {key, value -&gt; println key + " : " +
value}  

does not give me any entries..
So do you have an idea how to get to all the information's stored during
the steps ?

greetings 

Stefan Majer

On Mon, 2007-11-26 at 14:36 +0100, Florent Blondeau wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi,

If I understand what you want, I can share a workaround I found when 
using steps. Actually, I have some groovy code that call
webtest steps with ant, with a &lt;groovy&gt; step with some groovy code 
(That's a bit weird, but it
was to test if this kind of thing works).  I wanted to share variables 
between my groovy code and
the groovy step, for example.

you can do something like this before calling your ant.testSpec :

      ant.getAntProject().taskFinished = {buildEvent -&gt; def task = 
buildEvent.task
                                                          println "Task 
finished ............ $task.taskType"
                                                          if 
(task.taskType == 'testSpec'){
                                                                         
//that's fired when testSpec is finished, but you can
                                                                        
// do that for all your steps
                                                       
                                                                       
//an example of what you can do :
                                                                       
// you get all the properties defined in your tests
                                                                       
// useful when you want to feed a database, for instance
                                                                       
task.dynamicProperties.each {key, value -&gt; println key + " : " + value}  
                          
                                                          }
                                           }

      ant.getAntProject().taskStarted = { buildEvent -&gt;  def task = 
buildEvent.task
                                                           println "Task 
started ............ $task.taskType" }     

If you want to get the results, I saw there was a method called 
getResultBuilderListener() to get the listener which
contains the results. I didn't try but it could be a way to get that 
with task.builderListener.previousResponse or something
like that

It's really possible that a much simpler way exists, but I'm pretty new 
to webtest and I don't know all the possibilities. So
i don't claim that i hold the only truth ;-)

hope that helps

florent


Stefan Majer a écrit :
    </pre>
    <blockquote type="cite">
      <pre wrap="">Hi,

i want to access the stepResults eg. duration etc. in a simple groovy
webtest script like this:

ant.testSpec(name:'simple Groovy Webtest'){
    config(config_map)
    steps(){
        invoke(url:'linkpage.html')
        verifyText(description:"Index", text:"index")
        }
    }
}

Is it possible to get these for every called step ?

greetings 

Stefan Majer

_______________________________________________
WebTest mailing list
<a class="moz-txt-link-abbreviated" href="mailto:WebTest@lists.canoo.com">WebTest@lists.canoo.com</a>
<a class="moz-txt-link-freetext" href="http://lists.canoo.com/mailman/listinfo/webtest">http://lists.canoo.com/mailman/listinfo/webtest</a>
  
      </pre>
    </blockquote>
    <pre wrap="">
    </pre>
  </blockquote>
  <pre wrap=""><!---->
_______________________________________________
WebTest mailing list
<a class="moz-txt-link-abbreviated" href="mailto:WebTest@lists.canoo.com">WebTest@lists.canoo.com</a>
<a class="moz-txt-link-freetext" href="http://lists.canoo.com/mailman/listinfo/webtest">http://lists.canoo.com/mailman/listinfo/webtest</a>
  </pre>
</blockquote>
<br>
<br>
<pre class="moz-signature" cols="72">-- 
Pingwy
27, rue des arènes
49100 Angers
</pre>
</body>
</html>

--------------090400050303090408030504--