Automated Testing for Web Applications
by M. Selvakumar

Example 1:

TEST BEGIN
ID      : {id}
FEATURE : {Feature Name}
{KEY1}  : {VALUE1}
{KEY2}  : {VALUE2}
 ...
TEST END

Example 2:

TEST BEGIN
ID      : 1
FEATURE : "Search"
KEYWORD : "Web Development OR Internet Programming"
TEST END


Listing One
<html>
  <!-- ------------------------------------------------------------  
    Subject: pageA.html
    To     : Doctor Dobb's Journal
    Section: Internet Programming
    From   : M Selvakumar (selvak@india.ti.com)
    Copyright, 1998, M Selvakumar, Texas Instruments Inc.
  ------------------------------------------------------------- -->
<body >
  <center>
  <font size=5> Page A </font><br><hr>
  </center>
  <form method=post>
     Industry : <input type=text name="industry"> 
  </form>
  <hr>
</body>
</html>

Listing Two
<html>
  <!-- ------------------------------------------------------------  
    Subject: pageB.html
    To     : Doctor Dobb's Journal
    Section: Internet Programming
    From   : M Selvakumar (selvak@india.ti.com)
    Copyright, 1998, M Selvakumar, Texas Instruments Inc.
  ------------------------------------------------------------- -->
<head>
   <script language=JavaScript>
      var Win;
      // ---------------------------------------- 
      // Open 'Page A'
      // ---------------------------------------- 
      function init () {
           Win = window.open("http://<your domain>/pageA.html");
      }
      // ---------------------------------------- 
      // Modify 'Page A'
      // ---------------------------------------- 
      function modifyFormA () {
        // Set a value to form variable - Industry
        Win.document.forms[0].industry.value = "Software";
      } 
      // ---------------------------------------- 
      // Close 'Page A'
      // ---------------------------------------- 
      function term () { Win.close(); }
   </script>
</head>
<body >
  <center>
  <font size=5> Page B </font><br><hr>
  </center>
  <form name=formB action="">
    <input type=button value="Open PageA"             onClick="init();" ><br>
    <input type=button value="Set a Form Variable (Industry)"  onClick="modifyFormA();" ><br>
    <input type=button value="Close PageA"            onClick="term();" ><br>
  </form>
  <hr>
</body>
</html>

Listing Three
<html>
  <!-- ------------------------------------------------------------
    Subject: Online Shop 
    To     : Doctor Dobb's Journal
    Section: Internet Programming
    From   : M Selvakumar (selvak@india.ti.com)
    Copyright, 1998, M Selvakumar, Texas Instruments Inc.
  ------------------------------------------------------------- -->
  <head>
    <title> ABC Audio</title>
  </head>
  <body bgcolor="#ffffff">
  <center>
  <font size=6>ABC Audio</font><br>
  <font size=5>On-line Shopping!</font><br>
  </center>
  <br><hr>

  <font size=5>Personal Audio<font>
  <br><br>
  <font size=4>Please select the items & quantities</font>

  <form method=post action="http://<ABC Audio Domain Name>/cgi-bin/shop/onlineShop.pl">

  <blockquote>
  <!-- ---------------------------------------------
   // Display Brands and their prices
   --------------------------------------------- -->
  <table border=1>
    <tr bgcolor=yellow><th><th>Brand<th>Model Name<th>Price<th>Quantity

    <tr><td><input type=checkbox name=brands value="B1">
        <td> Sony
        <td> SA-1670
        <td> 20$
        <td><input type=text size=5 name="Q1">

    <tr><td><input type=checkbox name=brands value="B2">
        <td> Aiwa
        <td> AI-W660
        <td> 22$
        <td><input type=text size=5 name="Q2">
    <tr><td><input type=checkbox name=brands value="B3">
        <td> Panasonic
        <td> PA-X1250
        <td> 21$
        <td><input type=text size=5 name="Q3">
  </table>
  </blockquote>
  <br>
  <!-- ---------------------------------------------
   // Display Payment Methods
   --------------------------------------------- -->
  <font size=5> Payment Method<font>
  <blockquote>
     <input type=radio name=payment value="P1">Visa  
     <input type=radio name=payment value="P2">Master Card  
     <input type=radio name=payment value="P3">American Express  
  </blockquote>

  <hr>

  <input type=submit value="Order Now!">
  <input type=reset value="Clear">
  
  </form>
  </body>
</html>

Listing Four
<html>
  <!-- ------------------------------------------------------------  
    Subject: Online Shop Tester Program
    To     : Doctor Dobb's Journal
    Section: Internet Programming
    From   : M Selvakumar (selvak@india.ti.com)
    Copyright, 1998, M Selvakumar, Texas Instruments Inc.
  ------------------------------------------------------------- -->
   <head>
      <title> ABC Audio On-line Shop Tester </title>
      <script>
         var Win, RepWin;
         var count=0, noOfTests;
         // -------------------------------------------------- 
         // Main Function - Test Shop
         //   1. Generate and apply a random order
         //   2. Wait for the response
         //   3. Getback the Shop for next test
         // -------------------------------------------------- 
         function test( task ) {
            if ( task == 1 ){
               submitAShoppingReq();
               task = 2;
            }
            if (task == 2) {
               var ret = goBack();
               if ( ret == false ) {
                  setTimeout("test(2)", 2000);
                  return false;
               }
            }
            count++;
            // Move to next order
            if ( count <= document.forms[0].testCount.value) {
              setTimeout("test(1)", 500);
            }
            return true;
         }
         // -------------------------------------------------- 
         // Tester Function 1 - Open Shop
         // -------------------------------------------------- 
         function init() {
           Win = window.open("http://<ABC Audio Domain Name>/shop.html",'',
                             'width=500,height=600');
         }
         // -------------------------------------------------- 
         // Tester Function 2 - Generate a random order and 
         //                     apply to the Shop.
         // -------------------------------------------------- 
         function submitAShoppingReq() {
            var tmp = Math.round(Math.random()*10);
            var payment = tmp%3;

            Win.document.forms[0].reset();
            Win.document.forms[0].brands[0].checked=true;
            Win.document.forms[0].brands[1].checked=true;
            Win.document.forms[0].brands[2].checked=true;
            Win.document.forms[0].Q1.value= Math.round(Math.random()*300);
            Win.document.forms[0].Q2.value= Math.round(Math.random()*200);
            Win.document.forms[0].Q3.value= Math.round(Math.random()*100);
            Win.document.forms[0].payment[payment].checked = true;
            Win.document.forms[0].submit();
         }
         // --------------------------------------------------
         // Tester Function 3 - Close Shop
         // --------------------------------------------------
         function term() { Win.close(); }
         function goBack() {
            // Check if the response is received
            if ( typeof(Win.opOver) == 'undefined' ) {
               return false;
            }
            Win.history.go(-1);
            return true;
         }
      </script>
    </head>
    <body bgcolor="#ffffff">
         <center>
         <font size=5>ABC Audio On-line Shop </font><br>
         <font size=4>Web Interface Tester</font><br>
         </center>
         <br><hr>
         <form name=Tester onSubmit="parent.test()">
            <input type=button value="Open the Shop!" onClick="init();"><br>
            No. of Tests
            <input type=text name=testCount size=5 value=1>
            <input type=button value="Test!" onClick="count=1; test(1);"><br>
            <input type=button value="Close the Shop!" onClick="term();"><br>
            <br><hr>
         </form>
      </center>
    </body>
</html>



6


