Figure 2 Code for Web Application Under Test
public class WebForm1 : System.Web.UI.Page
{
... // controls declared here
public class Employee
{
public string last;
public string first;
public string dob;
public Employee(string last, string first, string dob)
{
this.last = last;
this.first = first;
this.dob = dob;
}
}
private ArrayList al = new System.Collections.ArrayList();
private void Page_Load(object sender, System.EventArgs e)
{
Employee e1 = new Employee("Adams","Terry","01/01/1971");
Employee e2 = new Employee("Burke","Brian","02/02/1972");
Employee e3 = new Employee("Ciccu","Alice","03/03/1973");
al.Add(e1);
al.Add(e2);
al.Add(e3);
Label3.Visible = false;
}
... // Web Form Designer generated code
private void Button1_Click(object sender, System.EventArgs e)
{
ListBox1.Items.Clear();
string filter = TextBox1.Text;
if (RadioButtonList1.SelectedValue == "Last Name")
{
foreach (Employee emp in al)
{
if (emp.last.IndexOf(filter) >= 0)
ListBox1.Items.Add(
emp.last + ", " + emp.first + ", " + emp.dob);
}
}
else if (RadioButtonList1.SelectedValue == "First Name")
{
foreach (Employee emp in al)
{
if (emp.first.IndexOf(filter) >= 0)
ListBox1.Items.Add(
emp.last + ", " + emp.first + ", " + emp.dob);
}
}
Label3.Visible = true;
}
}
Figure 3 Test Scenario Structure
using System;
using System.Threading;
using System.Diagnostics;
using SHDocVw;
using mshtml;
namespace RunTest
{
class Class1
{
static AutoResetEvent documentComplete = new AutoResetEvent(false);
[STAThread]
static void Main(string[] args)
{
try
{
// Launch IE
// Attach InternetExplorer object
// Establish DocumentComplete event handler
// Load app under test
// Manipulate the app
// Check the app's state
// Log 'pass' or 'fail'
// Close IE
}
catch(Exception ex)
{
Console.WriteLine("Fatal error: " + ex.Message);
}
}
private static void ie_DocumentComplete(object pDisp, ref object URL)
{
documentComplete.Set();
}
}
}