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

Florent Blondeau Florent Blondeau <fblondeau@pingwy.com>
Thu, 31 Jul 2008 09:07:03 +0200


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

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 = {buildEvent -> def task = 
buildEvent.task
                                                          println "Task 
finished ............ $task.taskType"
                                                           //testSpec is 
the main Step, but you can find anyone of your script's steps by this method
                                                            if 
(task.taskType == '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=task.getResultBuilderListener().getRootResult().getFailingTaskResult()
                                                              if 
(all_right==null){
                                                                   
//executing the query
                                                                  
sql.execute("""
                                                                    
update db set field=1
                                                                """)
                                                              }
                                                          }
                                                       
                                           }
    //triggered when task is about to begin
      ant.getAntProject().taskStarted = { buildEvent ->  def task = 
buildEvent.task
                                                           if 
(task.taskType == 'testSpec'){
                                                              webtest = task
                                                             
                                                              }
                                          }   

That may not be the simpliest way, but that brings control on the steps 
and their execution

Hope that helps

Florent

Pingwy
27, rue des arènes
49100 Angers



Mark Johnson a écrit :
> 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 not performing in the web test script because they are 
> getting called when the 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 web script?
>
> thanks for your help
>
> mark

--------------010502090909050009030601
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi mark,<br>
<br>
I've done that with several manners yet. The more flexible for me is
the "end of step interception".<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 &nbsp;&nbsp; &nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; &nbsp; ant.getAntProject().taskFinished = {buildEvent -&gt; def task =
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;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; println "Task
finished ............ $task.taskType"<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;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; //testSpec
is the main Step, but you can find anyone of your script'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;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
(task.taskType == 'testSpec'){<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;&nbsp;&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;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;
task.dynamicProperties.each {key, value -&gt; println key + " : " +
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;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; //test if
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;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; def
all_right=task.getResultBuilderListener().getRootResult().getFailingTaskResult()<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;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; if
(all_right==null){<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; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp; &nbsp;&nbsp;
//executing the query<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;&nbs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sp; }<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;&nbsp;&nbsp; &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;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &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;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
</small></small><small><small>&nbsp;&nbsp;&nbsp; //triggered when task is about to
begin</small></small><br>
<small><small>&nbsp;&nbsp;&nbsp; &nbsp; ant.getAntProject().taskStarted = { buildEvent
-&gt;&nbsp; def task = 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;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nb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sp;&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; <br>
<br>
<big><big>That may not be the simpliest way, but that brings control on
the steps and their execution<br>
<br>
Hope that helps<br>
<br>
Florent<br>
</big></big><br>
</small></small>
<pre class="moz-signature" cols="72">Pingwy
27, rue des ar&egrave;nes
49100 Angers
</pre>
<br>
<br>
Mark Johnson a &eacute;crit&nbsp;:
<blockquote
 cite="mid:6cb0efbf0807301629h4cecaa4dk6c808babe6faa967@mail.gmail.com"
 type="cite">
  <div dir="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>
</body>
</html>

--------------010502090909050009030601--