Web Testing, Part IV

There are two basic ways to test a Web application through the app’s UI. The first way is to write test automation which exercises the app using JavaScript to access the IE Document Object Model. This is effective but does have some limitations — you can only access the parts of the Web app’s functionality which are explicitly exposed through the IE DOM. The second way to write Web application UI automation is to directly call into the mshtml.dll and shdocvw.dll Windows libraries. Click on the image at the bottom of this entry to see what I mean. I call this technique "low-level Web UI testing".

I could write my harness using C++ and then call the mshtml.dll and shdocvw.dll functions directly. But this is difficult. An easier approach is to write a test harness using C#. The C# code uses the "P/Invoke" mechanism to call into the Win32 libraries — much easier. Launching the Internet Explorer browser looks something like this:

SHDocVw.InternetExplorer ie = null;

Process p = Process.Start("iexplore.exe", "about:blank");

if (p == null)

  throw new Exception("Could not launch IE");

Console.WriteLine("Process handle = " +



After you load the application under test, you can manipulate it like this:

Console.WriteLine("Clicking search button");

HTMLInputElement butt =





Conceptually, the technique is pretty easy but there are a lot of tricky details. For example, in the code snippet above, the WaitOne() method call is a key trick which halts the test harness thread of execution until after the click operation completes. You can’t pause using something like Thread.Sleep(2000) because there’s really no way to tell how long to pause.

I devote an entire chapter of my book ".NET Test Automation Recipes" to all the details of writing low-level Web application UI testing. See http://www.amazon.com/gp/product/1590596633/qid=1150213081/sr=2-1/ref=pd_bbs_b_2_1/103-1065536-4310244?s=books&v=glance&n=283155 for details.

This entry was posted in Software Test Automation. Bookmark the permalink.