Spy doesn't capture hierarchy WPF controls are placed in

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
HMITest
Posts: 3
Joined: Thu Oct 28, 2010 9:34 am

Spy doesn't capture hierarchy WPF controls are placed in

Post by HMITest » Thu Dec 05, 2013 9:02 am

Dear all,

we are asked to write an automated GUI test for a WPF application. The controls placed on the WPF form are not named and often have the same content/text displaying - but they are hierarchically placed in different "panels". Below I have included the XAML source code of a minimal working example showing the basic structure:

Code: Select all

<Window x:Class="SomeButtons.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="151" Width="190">
  <StackPanel Orientation="Vertical">
    <StackPanel Orientation="Horizontal">
      <Button Content="1" />
      <Button Content="2" />
    </StackPanel>
    <WrapPanel>
      <Button Content="1" />
      <Button Content="2" />
      <Button Content="Button" />
    </WrapPanel>
  </StackPanel>
</Window>
Until now the application - which is now made with WPF - was of the WinForms type, so that we could distinguish the buttons having the same button text by their position in the "panels" hierarchy (the Rx Path was different for them). As it seems the hierarchy is not persisted in WPF after compilation: The Ranorex Spy arranges the 5 controls on the same level, distinguishing them only by the index - here it's "1":

Code: Select all

/form[@name='MainWindow']/button[1]
The order is the exact one like the ordner in which they appear in XAML.
somebuttons.rxsnp
the snapshot for the first example
(7.79 KiB) Downloaded 196 times
Even when using a Grid like this:

Code: Select all

<Grid>
  <Grid.RowDefinitions>
    <RowDefinition />
    <RowDefinition />
  </Grid.RowDefinitions>
  <Button Content="Button" Grid.Row="1"/>
  <Button Content="Button" Grid.Row="0"/>
</Grid>
where the second Button is placed above the first button due to explicit Grid.Row="..." declaration, the order in which the Buttons got their indices in Spy is the order in which they appear in XAML: The button at the top of the window has the index 2 and the one place at the bottom was assigned index 1.
buttonsingrid.rxsnp
the snapshot for the second example
(10.03 KiB) Downloaded 131 times
This gives us a bit of a headache, since we cannot be as deterministic as with WinForms before, but maybe you have a solution for us? Would be awesome. Thanks!

Cheers,
David

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Spy doesn't capture hierarchy WPF controls are placed in

Post by Support Team » Tue Dec 10, 2013 1:52 pm

Hello HMITest,

The problem is that StackPanes is a layout panel and no ui element and there that there is no UIAutomation implementation available out of the box.
I am afraid that you have to create an Automation Peer for that element in order to recognize the element using Ranorex.

Regards,
Bernhard
.
Image