[Webtest] How to print/log in WebTest? + dbUnit to Webtest traverse update

Rob Manthey webtest@lists.canoo.com
Thu, 13 Jul 2006 11:56:03 +1000


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

Not sure if this answers your question but here's a patch from what I'm 
working on - it extracts some values from a dbUnit xml file and stores 
them in WebtestProperties and then uses them to test rendered content in 
the webpage.  As an aside, I logged to a local file (which is what you 
were asking about), as I had no luck getting diagnostic feedback from 
either echo or print.

my steps:

<groovy>
    def logFile = new File('./webtest.log')
    logFile.append("\nTest Start\n")
    
    def testData = new XmlParser().parse( new File('../../config/InHouseTesting.xml') )
    
    def customerId = 1001
    
    def testCustomer = testData.customerDetails.find{it['@customerID']==customerId}
    def testCustomerId = testCustomer.'@customerID'
    def testCustomerName = testCustomer.'@customerName'
    logFile.append("${testCustomerId} - ${testCustomerName}")
    // I can't get groovy's print to appear - some classpath dilemma no doubt
    // print "${testCustomerId} - ${testCustomerName}"
    
    step.setWebtestProperty('test_customer_id', testCustomerId)
    step.setWebtestProperty('test_customer_name', testCustomerName)    
    
    logFile.append("\nTest End\n")
</groovy>

<verifyProperty name="test_customer_id" text="1001" />
<verifyProperty name="test_customer_name" text="Canoo WebTest Customer 1" />

<verifyText description="dbUnit text must be present in the current webpage"
   text="#{test_customer_name}" />
   
<!-- these don't render the properties properly - I don't know why not? -->
<echo message="Test Customer Name = ${test_customer_name}" />
<echo message="Test Customer Name = #{test_customer_name}" />


Here's a sample chopped down from the dbUnit file (standard dbUnit file 
that loads xml into db for testing)

<?xml version='1.0' encoding='UTF-8'?>
<dataset>
 <customerDetails customerID="1001" customerName="Canoo WebTest Customer 1" contactName="Contact Name 1" contactAddress="1 Address St" />
 <customerDetails customerID="1002" customerName="Canoo WebTest Customer 2" contactName="Contact Name 2" contactAddress="2 Address St" />
 <customerDetails customerID="1003" customerName="Canoo WebTest Customer 3" contactName="Contact Name 3" contactAddress="3 Address St" />
 <customerDetails customerID="1004" customerName="Canoo WebTest Customer 4" contactName="Contact Name 4" contactAddress="4 Address St" />
 
 <userDetails username="webtest01" customerID="1001" fullName="WebTest User" userTypeSystem="user" />
 <userDetails username="webtest02" customerID="1001" fullName="WebTest Administrator" userTypeSystem="administrator" />

 <siteDetails siteID="1001" customerID="1001" siteName="Site 1001" />
 <siteDetails siteID="1002" customerID="1001" siteName="Site 1002" />
 <siteDetails siteID="1003" customerID="1001" siteName="Site 1003" />
</dataset>



on 13/07/06 01:46 dlundin@aol.com said the following:
> Hello,
>  
> I've done some poking around on the site but haven't found an answer 
> to this question ...
>  
> I'm using storeXPath to save a value into a property. Now, how to I 
> print/log it in an output file? I've seen reference that such logging 
> is possible.
>  
> Thanks in advance
> Doug
> ------------------------------------------------------------------------
> *Check out AOL.com today* 
> <http://pr.atwola.com/promoclk/1615326657x4311227241x4298082137/aol?redir=http%3A%2F%2Fwww%2Eaol%2Ecom>. 
> Breaking news, video search, pictures, email and IM. All on demand. 
> Always Free.

--------------000508040609060309060500
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">
Not sure if this answers your question but here's a patch from what I'm
working on - it extracts some values from a dbUnit xml file and stores
them in WebtestProperties and then uses them to test rendered content
in the webpage.&nbsp; As an aside, I logged to a local file (which is what
you were asking about), as I had no luck getting diagnostic feedback
from either echo or print.<br>
<br>
my steps:<br>
<pre>&lt;groovy&gt;
&nbsp;&nbsp;&nbsp; def logFile = new File('./webtest.log')
&nbsp;&nbsp;&nbsp; logFile.append("\nTest Start\n")
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; def testData = new XmlParser().parse( new File('../../config/InHouseTesting.xml') )
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; def customerId = 1001
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; def testCustomer = testData.customerDetails.find{it['@customerID']==customerId}
&nbsp;&nbsp;&nbsp; def testCustomerId = testCustomer.'@customerID'
&nbsp;&nbsp;&nbsp; def testCustomerName = testCustomer.'@customerName'
&nbsp;&nbsp;&nbsp; logFile.append("${testCustomerId} - ${testCustomerName}")
&nbsp;&nbsp;&nbsp; // I can't get groovy's print to appear - some classpath dilemma no doubt
&nbsp;&nbsp;&nbsp; // print "${testCustomerId} - ${testCustomerName}"
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; step.setWebtestProperty('test_customer_id', testCustomerId)
&nbsp;&nbsp;&nbsp; step.setWebtestProperty('test_customer_name', testCustomerName)&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; logFile.append("\nTest End\n")
&lt;/groovy&gt;

&lt;verifyProperty name="test_customer_id" text="1001" /&gt;
&lt;verifyProperty name="test_customer_name" text="Canoo WebTest Customer 1" /&gt;

&lt;verifyText description="dbUnit text must be present in the current webpage"
&nbsp;&nbsp; text="#{test_customer_name}" /&gt;
&nbsp;&nbsp; 
&lt;!-- these don't render the properties properly - I don't know why not? --&gt;
&lt;echo message="Test Customer Name = ${test_customer_name}" /&gt;
&lt;echo message="Test Customer Name = #{test_customer_name}" /&gt;
</pre>
<br>
Here's a sample chopped down from the dbUnit file (standard dbUnit file
that loads xml into db for testing)<br>
<br>
<pre>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
&lt;dataset&gt;
 &lt;customerDetails customerID="1001" customerName="Canoo WebTest Customer 1" contactName="Contact Name 1" contactAddress="1 Address St" /&gt;
&nbsp;&lt;customerDetails customerID="1002" customerName="Canoo WebTest Customer 2" contactName="Contact Name 2" contactAddress="2 Address St" /&gt;
 &lt;customerDetails customerID="1003" customerName="Canoo WebTest Customer 3" contactName="Contact Name 3" contactAddress="3 Address St" /&gt;
&nbsp;&lt;customerDetails customerID="1004" customerName="Canoo WebTest Customer 4" contactName="Contact Name 4" contactAddress="4 Address St" /&gt;
 
 &lt;userDetails username="webtest01" customerID="1001" fullName="WebTest User" userTypeSystem="user" /&gt;
 &lt;userDetails username="webtest02" customerID="1001" fullName="WebTest Administrator" userTypeSystem="administrator" /&gt;

 &lt;siteDetails siteID="1001" customerID="1001" siteName="Site 1001" /&gt;
 &lt;siteDetails siteID="1002" customerID="1001" siteName="Site 1002" /&gt;
 &lt;siteDetails siteID="1003" customerID="1001" siteName="Site 1003" /&gt;
&lt;/dataset&gt;</pre>
<br>
<br>
on 13/07/06 01:46 <a class="moz-txt-link-abbreviated" href="mailto:dlundin@aol.com">dlundin@aol.com</a> said the following:
<blockquote cite="mid8C873E185819F59-63C-6C9D@FWM-R10.sysops.aol.com"
 type="cite">
  <div>Hello,</div>
  <div>&nbsp;</div>
  <div>I've done some poking around on the site but haven't found an
answer to this question ... </div>
  <div>&nbsp;</div>
  <div>I'm using <font size="2">storeXPath to save a value into a
property. Now, how to I print/log it in an output file? I've seen
reference that such logging is possible.</font></div>
  <div>&nbsp;</div>
  <div>Thanks in advance</div>
  <div>Doug</div>
  <div class="AOLPromoFooter">
  <hr style="margin-top: 10px;"><a
 href="http://pr.atwola.com/promoclk/1615326657x4311227241x4298082137/aol?redir=http%3A%2F%2Fwww%2Eaol%2Ecom"
 target="_blank"><b>Check out AOL.com today</b></a>. Breaking news,
video search, pictures, email and IM. All on demand. Always Free.<br>
  </div>
</blockquote>
</body>
</html>

--------------000508040609060309060500--