XML Test Suite

Home
Install
Intro
 API
 DTD
Project
Releases
 Compiled
 Source

SourceForge Logo

XmlTestSuite provides a powerful way to test web applications. 

This page illustrates how to use the XmlTestSuite  to test a web site.
It assumes that you have already installed the application.

The first step is to create an XML file. You could use a simple test editor
such as notepad or vi, but a syntax checking editor such as jEdit is preferable. For syntax checking, the DOCTYPE should point to a valid dtd file; (use YOUR-XMLTESTSUITEHOME/lib/test.dtd)

The following two examples illustrate two simple xml test files.
<?xml version="1.0" ?>
<!DOCTYPE testSpec SYSTEM "test.dtd">
<testSpec>
        <steps>
                <fetch url="http://server/..."/>
                 <verifylinks/>

        </steps>
</testSpec>
<?xml version="1.0" ?>
<!DOCTYPE testSpec SYSTEM "test.dtd">
<testSpec>
        <steps>
                <fetch url="http://server/..."/ 
                   htmlwarnings="true">
                <verify> 
                     <frameset name="mainframeset"> 
                        <frame name="top" url="..." /> 
                        <frame name="main" url="..." /> 
                    </frameset>
                 </verify> 

        </steps>
</testSpec>

The example on the left fetches a page, and then recursively checks all of the links on the page.
The example on the right fetches a page, and displays any warnings if the HTML  has any errors, and then verifies that the page returned from the web server is a frameset and contains frames called 'top' and 'main'. 

To run the tests from the command line type

	xmltestsuite testFileName.xml

(to test all xml files in a directory, specify the directory e.g. "xmltestsuite .")

This assumes that the XmlTestSuite bin directory is in your shell's PATH.
Alternatively, java can be invoked directly. The first line below invokes the GUI test runner that comes as part of junit

    java com.netriser.xmltestsuite.Main [-v|-verbose] [-h|-help] [xmlPathname]
    java [-Dv] [-Dd] [-Dfile=xmlpathname] com.netriser.xmltesttuite.Main
    java [-Dv] [-Dd] [-Dfile=xmlpathname] junit.textui.TestRunner
com.netriser.xmltesttuite.Main
    java [-Dv] [-Dd] [-Dfile=xmlpathname] junit.swingui.TestRunner -noloading
com.netriser.xmltesttuite.Main

The next example may appear unusual for a web testing tool. It tests a database stored procedure.
One of the strengths of XmlTestSuite is that it can be used to test database interfaces as well as web interfaces. This allows stored procedures, views and user defined functions can be written and tested, before incorporating into web pages.

    <?xml version="1.0" ?>
    <!DOCTYPE testSpec SYSTEM "test.dtd">
    <testSpec  application="..." baseURL="http://server/">
            <database dbdriver = "..." dbconnection = "...">
                   <dbTable name="Contacts" identity="ContactId"/>
                   <dbTable name="Suppliers" identity="SupplierId"/>
                   <dbTable name="log" identity="LogId"/>
            </database>
              <steps stepid="testAll">

                        <!-- Call a stored procedure to enter data into database 
                                specify that an insertion is expected in Suppliers and Contacts tables
                        
-->
                        <exec query="exec insertNewSupplier 'SupplierName', 'ContactName' ">
                           
<dbInsert id="newSupplierId" dbTable="Suppliers"/>
                            <dbInsert id="newContactId" dbTable= "Contacts"/>

                      </exec>

                     <!-- Verify that a search by supplier gives the expected contact record
                     -->
                    
<set name="supplierId" query="
                              
select contactid fromSuppliers sjoin Contacts con s.contactid= c.idwhere name= 'SupplierName' "/>  < BR >                      <eval  expr="${contactid} = ${newContactId}"
            </steps>
    <testSpec/>

  • The script executes a stored procedure which takes a supplier name and a contact name.
    The dbInsert tags specify the tables into which we expect the stored procedure to insert new rows.
    If rows are not inserted, or rows are inserted into other tables, an error will be generated.
  • The set tag illustrates how values can be extracted from the database; in this case it is verifying that we can find the contact we just inserted, from the supplier name.
  • The eval tag is used to check that the identifierof the contact from the dbInsert tag matches the identifier of the contact retrieved by the query.

One important issue with database testing is how to clean up the database as you test.
XmlTestSuite will print out an sql script for all the monitored database tables, which can be used to remove inserted rows. [This feature also works when the database is updated indirectly via a web page]

The following is a more complex example, which brings together web and database testing. It verifies the contents of the fetched pages, and the changes to certain database tables.

    <?xml version="1.0" ?>
    <!DOCTYPE testSpec SYSTEM "test.dtd">
    <testSpec  application="..." baseURL="http://server/">
            <database dbdriver = "..." dbconnection = "...">
                   <dbTable name="Customers" identity="CustomerId"/>
                   <dbTable name="Suppliers" identity="SupplierId"/>
                    <dbTable name="log" identity="LogId"/>
            </database>
            <definePage name="login" url="...>
                        <form id="form" name="form" action="..." method="post">
                                <dbInsert dbTable="log" id="userid"/>
                                <input name="Name" type="text" set="..."/>
                                <input name="Password" type="text" set="..."/>
                        </form> 
            </definePage>
            <definePage name="default" url="...">      
                        <frameset url="default.cfm" name="mainframeset">
                                <frame page="newCustomer" name="..."  url="..." />
                                <frame name="header"/>
                                <frame name="hidden"/>
                        </frameset>
             </definePage>
            <definePage name="newCustomer" url="...>
                        <form id="form" name="customerform" action="..." method="post">
                               <dbInsert dbTable="Customers" id="newcustomerid"/>
                               <input name="Customer" type="text" set="#{cname}"/>
                                <input name="Telephone" type="text" set="#{ctel}."/>
                        </form> 
            </definePage>
            <steps stepid="testAll">
                        <with page="login"/>
                                <fetch/<verify/> <submit/>
                        </with>
                        <verify page="default"/>
                        <set name="cname" value="..."/>
                        <set name="ctel" value="..."/>
                        <submit form="customerform"/>
                        <set name="dbQueryID"
                                query="select CustomerId from Customers name='#{cname}' and tel='#{ctel}'/>
                        <eval  expr="${dbQueryID} = ${newcustomerid}"
            </steps>
    <testSpec/>

 

The <database> element specifies that the Customers, Suppliers, and Log database tables will be monitored. The <definePage> elements define the structure of a login page and a frameset page. 

The <steps> elements 

  • verifies an initial login page, 
  • submits a username and password, verifies that an entry is made in the log table
  • verifies that the initial page is a frameset,
  • verifies that the main frame has a "New Customer" form
  • Submits the details of a new customer
  • Verifies that an entry was made in the customers table
  • Queries the database to ensure that the supplied values were inserted

The DTD documentation has more details and examples of what can be used in a xml test script.

 

Copyright (c)  Netriser Limited