2

In automation of a WPF application (using UI Automation; VSTS 2010), we were adding all the Automation IDs in a Resource File manually and then access it one by one. Considering the application can expand any time, manually adding these IDs can become tedious.

So, is there any tool available which can create this for us? i.e. Get all the ids in a hierarchical format and store it in a file (xml or csv), and then we could parse it whenever required.

I was hoping for a tool like UISpy, which not only can spy all the elements but also export the same.

Do such tools exist? Or is there any alternate approach?

Any valuable feedback is highly appreciated.

Thanks!

Srees
  • 21
  • 1

3 Answers3

1

I do like this:

public static class AutomationIds
{
    public static readonly string MyDataGridId= Create();

    private static string Create([CallerMemberName] string name = null)
    {
        return name;
    }
}

<DataGrid AutomationProperties.AutomationId="{x:Static local:AutomationIds.MyDataGridId}"
          ... />

Then in tests

var dataGrid = window.Get<ListView>(AutomationIds.MyDataGridId);
Johan Larsson
  • 17,112
  • 9
  • 74
  • 88
0

Assign the automation IDs directly in XAML, then parse XAML files since they are XML after all...

m0sa
  • 10,712
  • 4
  • 44
  • 91
  • m0sa.. thanks for your reply.. But the thing is, we have multiple XAML files and how can we get the automation ids in a hierarchical format? – Srees Nov 20 '12 at 07:07
0

Let's see... First, I think that your data is not hierarchical - just because a control can be dynamically assigned to be a child of another.

If we change the problem to a subset: "how can we get a hierarchical view of the controls at a time t?" then we can answer this with MS UIA, and say, using a simple RawViewWalker (just a simple breadth-first search on the walker, starting from your main window will do - of course while the application is running so that UIA can reach and query it).

But this subset will not satisfy your initial question, because you'll probably see a portion of your whole ui collection (since some will be hidden / not activated yet at time t).

So it becomes very hard to use a UIA based tool (such as uispy) because then you'll have to set the application view to different states to reach all the controls in your application at different times t1, t2...

I would suggest parsing all your xmls at the same time and build a complete tree of the application's "static" control map, which I believe would be closest to what you're asking for.

Given that this is an old question, I doubt it matters anymore, but just wanted to make the distinctions here.

AlbusMPiroglu
  • 645
  • 3
  • 13