Search code examples
c#ui-automationwhite-framework

Use Teststack White with Windows File Explorer


I'm unable grab onto the File Explorer window with the White framework. I used the Window's 10 SDK Inspect tool on the File Explorer to get this: Inspect Image

As you can notice the window Name is empty.

In order to grab the window, at least from their docs, you need to use GetWindow with the Name. I used this code block:

Application application = Application.Launch("C:\\Window\\explorer.exe");
System.Threading.Thread.Sleep(10000);
List<Window> windows = Desktop.Instance.Windows();
for (int i = 0; i < windows.Count; i++)
    Console.WriteLine(i + ". " + windows[i]);
Window fileExplorer = application.GetWindow("");

The loop output displays all windows: (2. most likely being the File Explorer)

0: C:\Users\admin\Documents\Visual Studio 2017\foo.exe

1: foo (Running) - Microsoft Visual Studio

2:

3: Program Manager

And GetWindow displays this:

Couldn't find window with title in process 6296, after waiting for 30 seconds

I've gotten Teststack White to work with other application when the Name is given in inspect so it doesn't seem to be a problem with Teststack White but with the File Explorer because it has no Name. Though, is there any other way to get TestStack to grab the File Explorer window.

TL;DR: How do I get the TestStack White framework to grab the Window's File Explorer window in order to send commands to it?


Solution

  • TestStack White is too limited. Switched over to Microsoft's UI Automation. Using

    var fileExplorer = 
    AutomationElement.RootElement.FindFirst(TreeScope.Children, 
    new PropertyCondition(AutomationElement.NameProperty, "File Explorer"));
    

    to get the File Explorer.