[Webtest] Newbie needing help with reports

Troy McGuire webtest@lists.canoo.com
Thu, 04 May 2006 09:17:19 -0700


Below is my script for reporting with some heavy comments for new 
users.  Anyone else more experienced than I is more than welcome to 
point out any corrections that are needed, or desired.

Here it is:
******************************************************************************************
<?xml version="1.0"?>
<!DOCTYPE project SYSTEM 
"/usr/local/sbin/canoo_webtest/selftests/config/WebTest.dtd">

<!-- Hey Newbie! The comments I've added for you start "NEWBIE", the 
rest of the comments are what's normally in this file.  Most of what's 
here is for reporting and setting up everything needed for an 
encrypted/secure connection.  The actual test is the last target 
tag-pair.  I hope this helps!  -->
   

<project name="customer_loginpage" basedir="." default="testSuite">
    <!-- NEWBIE - This part mostly saves path names in variables to make 
the rest of the script easy to write (and easier to change if something 
moves to another path later in life). -->
    <property name="webtest.home" 
location="/usr/local/sbin/canoo_webtest" />
    <property name="test.dir" 
location="/usr/local/www/customeradvertising.com/qa/canoo_webtest" />
    <property name="test.file" value="customer_loginpage.xml" />
    <property name="webtest.resultpath" 
value="${test.dir}/webtest-results"/>
    <property name="webtest.resultfile" value="results.xml"/>
    <property name="webtest.resultfile.html" 
value="${webtest.resultpath}/results.html"/>
    <import file="${webtest.home}/lib/taskdef.xml" />
   
    <!-- NEWBIE - This target sets parameters for performing a SSL/https 
login.  The parameters are set to handle the certificate and 
authentication.  If you're site isn't using any secure 
connection/encryption then this can all be removed, or commented out -->
    <target name="callBaseHttps" description="Sets up everything needed 
for SSL connection">
        <antcall target="https">
            <param name="webtest.port" value="${webtest.ssl.port}" />
            <param name="webtest.protocol" value="https" />
            <param name="webtest.truststore.file" value="trust.keystore" />
            <param name="webtest.truststore.passphrase" 
value="yourPasswordHere" />
            <param name="webtest.connectioninitializer" 
value="com.canoo.webtest.security.SunJsseBaseConnectionInitializer" />
            <param name="webtest.keystore.alias" value="customerkey" />
        </antcall>
    </target>
   
    <!-- NEWBIE - Most of what's in this script I copied from one of the 
XML files that came with Canoo 
(.../canoo_webtest/resources/webtestRunner.xml).  Currently this script 
only runs one test, but I think it can be easily modified (by removing, 
and changing, some of the comments near the bottom) to handle a suite of 
tests.  The rest of what I pasted from that file is for transforming the 
XML output into HTML.  Look at the descriptions in the opening target 
tag to get a basic idea of what's going on.  This target just checks to 
see if variables for a test file and test directory are set. -->
    <target name="init" description="Checks that needed properties are 
defined">
        <fail message="test.file should be set" unless="test.file" />
        <fail message="test.dir should be set" unless="test.dir" />
    </target>

    <!-- NEWBIE - This is the equivalent to a "main" function in C.  The 
"depends" attribute tells Webtest to call the "init" target (the target 
directly above) before executing.  Then executes targets appearing later 
in this file. -->
    <target name="testSuite" depends="init" description="Runs the Test 
Suite">
        <mkdir dir="${webtest.resultpath}" />
        <antcall target="cleanUp" />
        <antcall target="loginPageTest" />
        <antcall target="formatResults" />
    </target>
   
    <!-- NEWBIE - I think I took out the "webtest.skipCleanup" variable, 
this removes files from the previous run. -->
    <target name="cleanUp" description="Deletes all generated files" 
unless="webtest.skipCleanup">
        <delete>
            <fileset dir="${webtest.resultpath}" includes="**/*.*ml" />
        </delete>
    </target>
   
    <!-- NEWBIE - This target is what takes the XML results file and 
makes it into HTML.  Don't know why this isn't setup as a standard for 
all scripts after install, especially since after installation it can be 
found in the webtestRunner.xml file  -->
    <target name="formatResults" description="Formats the XML result 
file using XSL">
        <tstamp>
            <format property="report.time" pattern="dd.MM.yyyy HH:mm" 
locale="us" />
        </tstamp>
        <property name="resources.dir" value="${webtest.home}/resources"/>
        <style
                basedir="${webtest.resultpath}"
                destdir="${webtest.resultpath}"
                includes="${webtest.resultfile}"
                force="true"
                extension=".html"
                style="${resources.dir}/WebTestReport.xsl">
            <param name="reporttime" expression="${report.time}"/>
            <param name="title" expression="${ant.project.name}"/>
        </style>
        <!-- copy resources needed by the html page to the same dir: the 
report must be ok too when opened from filesystem (without webserver) -->
        <copy todir="${webtest.resultpath}">
            <fileset dir="${resources.dir}">
                <include name="report.css"/>
                <include name="showHide.js"/>
                <include name="images/*.*"/>
            </fileset>
        </copy>       
        <echo message="Webtest result overview available in 
${webtest.resultfile.html}"/>
    </target>

    <!-- NEWBIE - Here is the actual test.  The config sets up what URL 
to test, and what directory might appear after the base URL.  The 
"invoke" shows what file in the URL to use.  In this case it's 
https://secure.customerdealerdb.com/admin/index.php  The "verifyTitle" 
is the crux of the test, where data is actually compared/verified  -->
    <target name="loginPageTest" description="Checks that the login page 
is loaded" depends="init">
        <echo message="Start execution of '${test.file}' in dir 
'${test.dir}'"/>
        <!-- <ant antfile="${test.file}" dir="${test.dir}"/> -->
        <webtest name="customer_loginpage">
            <config
                host="secure.customerdealerdb.com"
                port="443"
                protocol="https"
                basepath="admin"
                summary="true"
                resultfile="results.xml">
                <header name="followRedirects" value="true" />
            </config>
            <steps>
                <invoke
                    description="Get Login Page"
                    url="index.php" />
                <verifyTitle
                    description="Verify Login Page Title"
                    text="Customer :: Dealer Database Administration" />
            </steps>
        </webtest>
    </target>
</project>
******************************************************************************************

Enjoy!

Troy
troy AT spawnordie DOT com


Lindsay Donaghe wrote:
> Hi All,
>  
> I just started looknig at WebTest yesterday and I have to say that so 
> far I am very impressed.  There seems to be a lot of flexibility here 
> and it's very well done.
>  
> I have been able to create some simple tests and run them in the 
> command line.  I just figured out how to alter the config properties 
> to output the results as XML, but I need to know what I can do with 
> those..
>  
> It looks like there are some HTML reporting capabilities but I can't 
> figure out how to make it work... and there's a screenshot of a nice 
> looking results viewer on the wiki, but I can't find where it can be 
> downloaded...
>  
> Can someone point me in the right direction for getting some easy to 
> understand results out of this?  The command line thing just doesn't 
> do it for me.
>  
> Thanks!!
> Lindsay