[Webtest] Best way to check a database in a webtest

Mark Johnson Mark Johnson" <markfjohnson@gmail.com
Thu, 31 Jul 2008 09:17:00 -0400


------=_Part_3622_3798940.1217510220543
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

Wow! that is so cool.  Not only does it solved my question, but it also
enabled the solution for some tasks I considered impossible.  I have wanted
to capture some information about the tasks for performance and traceabilit=
y
reporting.  My plan was to do this in the XSLT report script, but this is
much better.

Thanks for your great reply!

mark

On Thu, Jul 31, 2008 at 3:07 AM, Florent Blondeau <fblondeau@pingwy.com>wro=
te:

>  Hi mark,
>
> I've done that with several manners yet. The more flexible for me is the
> "end of step interception".
> You can put listeners on steps processed with Ant like :
>
> def webtest
>         //triggered when task has finished
>       ant.getAntProject().taskFinished =3D {buildEvent -> def task =3D
> buildEvent.task
>                                                           println "Task
> finished ............ $task.taskType"
>                                                            //testSpec is
> the main Step, but you can find anyone of your script's steps by this met=
hod
>                                                             if
> (task.taskType =3D=3D 'testSpec'){
>                                                               //here I
> print the value of the stored properties at the end of the test
>
> task.dynamicProperties.each {key, value -> println key + " : " + value}
>                                                               //test if
> there is a failing task in the script
>                                                                 def
> all_right=3Dtask.getResultBuilderListener().getRootResult().getFailingTas=
kResult()
>                                                               if
> (all_right=3D=3Dnull){
>
> //executing the query
>
> sql.execute("""
>                                                                     updat=
e
> db set field=3D1
>                                                                 """)
>                                                               }
>                                                           }
>
>                                            }
>     //triggered when task is about to begin
>       ant.getAntProject().taskStarted =3D { buildEvent ->  def task =3D
> buildEvent.task
>                                                            if
> (task.taskType =3D=3D 'testSpec'){
>                                                               webtest =3D
> task
>
>                                                               }
>                                           }
>
> That may not be the simpliest way, but that brings control on the steps a=
nd
> their execution
>
> Hope that helps
>
> Florent
>
>  Pingwy
> 27, rue des ar=E8nes
> 49100 Angers
>
>
>
> Mark Johnson a =E9crit :
>
> I have a groovy based webtest which needs to verify that the database has
> been properly updated.  I am assuming that my groovy db SQL queries are n=
ot
> performing in the web test script because they are getting called when th=
e
> antbuilder is preparing the test.  Is this a correct assumption?  If so,
> does anyone have an alternate strategy for doing a sql query within the w=
eb
> script?
>
> thanks for your help
>
> mark
>
>

------=_Part_3622_3798940.1217510220543
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Content-Disposition: inline

<div dir=3D"ltr">Wow! that is so cool.&nbsp; Not only does it solved my que=
stion, but it also enabled the solution for some tasks I considered impossi=
ble.&nbsp; I have wanted to capture some information about the tasks for pe=
rformance and traceability reporting.&nbsp; My plan was to do this in the X=
SLT report script, but this is much better.<br>
<br>Thanks for your great reply!<br><br>mark<br><br><div class=3D"gmail_quo=
te">On Thu, Jul 31, 2008 at 3:07 AM, Florent Blondeau <span dir=3D"ltr">&lt=
;<a href=3D"mailto:fblondeau@pingwy.com">fblondeau@pingwy.com</a>&gt;</span=
> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"border-left: 1px solid rgb(204, =
204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">


 =20

<div bgcolor=3D"#ffffff" text=3D"#000000">
Hi mark,<br>
<br>
I&#39;ve done that with several manners yet. The more flexible for me is
the &quot;end of step interception&quot;.<br>
You can put listeners on steps processed with Ant like :<br>
&nbsp;&nbsp;&nbsp; &nbsp; <br>
<small><small>def webtest<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //triggered when task has finished &n=
bsp;&nbsp; &nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp; ant.getAntProject().taskFinished =3D {buildEvent =
-&gt; def task =3D
buildEvent.task<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; println &quot;Task
finished ............ $task.taskType&quot;<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; //testSpec
is the main Step, but you can find anyone of your script&#39;s steps by
this method<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
(task.taskType =3D=3D &#39;testSpec&#39;){<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //here I
print the value of the stored properties at the end of the test<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
task.dynamicProperties.each {key, value -&gt; println key + &quot; : &quot;=
 +
value}<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //test i=
f
there is a failing task in the script<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nb=
sp; def
all_right=3Dtask.getResultBuilderListener().getRootResult().getFailingTaskR=
esult()<br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&n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p; }<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;=
 &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp=
; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbs=
p; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
</small></small><small><small>&nbsp;&nbsp;&nbsp; //triggered when task is a=
bout to
begin</small></small><br>
<small><small>&nbsp;&nbsp;&nbsp; &nbsp; ant.getAntProject().taskStarted =3D=
 { buildEvent
-&gt;&nbsp; def task =3D buildEvent.task<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbs=
p;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nb=
sp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if
(task.taskType =3D=3D &#39;testSpec&#39;){<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp=
;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&n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brings control on
the steps and their execution<br>
<br>
Hope that helps<br>
<br>
Florent<br>
</big></big><br>
</small></small>
<pre cols=3D"72">Pingwy
27, rue des ar=E8nes
49100 Angers
</pre>
<br>
<br>
Mark Johnson a =E9crit&nbsp;:
<div class=3D"Ih2E3d"><blockquote type=3D"cite">
  <div dir=3D"ltr">I have a groovy based webtest which needs to verify
that the database has been properly updated.&nbsp; I am assuming that my
groovy db SQL queries are not performing in the web test script because
they are getting called when the antbuilder is preparing the test.&nbsp; Is
this a correct assumption?&nbsp; If so, does anyone have an alternate
strategy for doing a sql query within the web script?<br>
  <br>
thanks for your help<br>
  <br>
mark<br>
  </div>
</blockquote>
</div></div>

</blockquote></div><br></div>

------=_Part_3622_3798940.1217510220543--