Low Level Web Application UI Test Automation on Vista

Software test automation has five key advantages over manual software testing and these advantages are summarized by the acronym SAPES: speed, accuracy, precision, efficiency, and skill-building. One of the four fundamental types of software test automation is Web Application UI automation. (The other three fundamental types are API/unit/module testing, Windows application UI testing, and HTTP request-response testing). If you write custom Web application UI automation (as opposed to using a framework written by someone else), you can either use a high level JavaScript approach to manipulate the browser DOM, or you can use low level calls into Win32 functions contained in the SHDocVw.dll interop assembly. The low level approach works fine on Windows XP but there are some unresolved (by me anyway) issues using the approach on Vista. A key part of the technique involves the test harness launching an instance of Internet Explorer and then attaching to that process. For example, the code below works fine on XP but invariably barfs on Vista. I’ll update this blog if I figure what’s going on.
Console.WriteLine("Begin demo");
Process p = Process.Start("iexplore.exe", "about:blank");
ShellWindows allShells = new ShellWindows();
Console.WriteLine("There are " + allShells.Count + " browser shells active");
Console.WriteLine("Attaching to IE process");
InternetExplorer ie = null;
int i = 0;
while (i < allShells.Count && ie == null) {
  InternetExplorer e = (InternetExplorer)allShells.Item(i);
  if (e.HWND == (int)p.MainWindowHandle) {
    Console.WriteLine("Found the IE process I launched");
    ie = e;
  else {
    Console.WriteLine("Wrong shell . . .");
if (ie == null)
  Console.WriteLine("Fatal logic: never found target IE process");
  Console.WriteLine("Success: target IE process has HWND = " + ie.HWND); 
This entry was posted in Software Test Automation. Bookmark the permalink.

3 Responses to Low Level Web Application UI Test Automation on Vista

  1. Chen says:

    I\’m reading your article for the UI automation. But, as you said the web low level launcher doesn\’t work on Vista. waiting for your update on this..And, another concern is to how to get the second IE or dlg launched from the DOM actions…it makes me confused.

  2. says:

    I have read your book of Test Automation, and I\’m interested in your low level web UI test. It looks good.
    I tried your code in VS 2005 under Vista, found that the Process.MainWindowHandle always returned 0 after IE is launched by Process.start(), the real handle value can be catched by Spy++.
    Another problem I encountered was that after the web page was loaded completely, it seems the AutoResetEvent was not SET, so the program kept waiting the set signal.
    I\’m tring find a way to resolve them now, I googled and luckly find your blog here. Could you share your solution once you have? I\’ll regularly read this blog.

  3. George says:

    Process.MainWindowHandle always return 0 after IE is launched…any update on this, James?

Comments are closed.