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");
Thread.Sleep(3000);
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 . . .");
++i;
}
}
if (ie == null)
Console.WriteLine("Fatal logic: never found target IE process");
else
Console.WriteLine("Success: target IE process has HWND = " + ie.HWND);
Process p = Process.Start("iexplore.exe", "about:blank");
Thread.Sleep(3000);
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 . . .");
++i;
}
}
if (ie == null)
Console.WriteLine("Fatal logic: never found target IE process");
else
Console.WriteLine("Success: target IE process has HWND = " + ie.HWND);
.NET Test Automation Recipes
Software Testing
SciPy Programming Succinctly
Keras Succinctly
R Programming
2026 Visual Studio Live
2025 Summer MLADS Conference
2026 DevIntersection Conference
2025 Machine Learning Week
2025 Ai4 Conference
2026 G2E Conference
2026 iSC West Conference
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.
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.
Thanks!
Jack
Process.MainWindowHandle always return 0 after IE is launched…any update on this, James?