我正在使用Coded UI Testing(可在Microsoft Visual Studio 2015 Enterprise中使用)并使用刻录机创建测试。我的测试完全适用于我的WPF应用程序,除非我使用过" IntegerUpDown"来自Extended.Wpf.Toolkit控件的控件。
遇到此类问题时的常规方法是在XAML中的控件中添加可选属性AutomationId。然后,下次录制测试时,它会使用该ID,从而唯一地标识您的XAML控件。例如,我的按钮......
<Button Width="75" Height="40">Click Me</Button>
简单地变成......
<Button Width="75" Height="40" AutomationProperties.AutomationId="Btn1">Click Me</Button>
我的IntegerUpDown控件......
<xctk:IntegerUpDown/>
变成......
<xctk:IntegerUpDown AutomationProperties.AutomationId="Nuid1" />
这很容易,适用于所有控件,如按钮等,但不适用于我使用过的IntegerUpDown控件。在IntegerUpDown的情况下,CodedUI测试会看到&#34; AutoSelectTextBox&#34;的自动化ID。而不是价值&#34; Nuid1&#34;我已经设定了。这个&#34; AutoSelectTextBox&#34;来自为什么我不能像我对标准WPF控件那样设置AutomationID?
无法设置AutomationID的问题是记录的测试有时无法判断哪个控件是哪个。为了澄清,当我在录制时通过从编码的UI测试生成器上的目标按钮拖动来记录编码的ui测试时,我可以看到AutomationID,我也可以在下面的搜索属性中看到它...
this.mUIAutoSelectTextBoxEdit.SearchProperties[WpfEdit.PropertyNames.AutomationId] = "AutoSelectTextBox";
问题是&#34; AutoSelectTextBox&#34;不是我输入的,我进入&#34; Nuid1&#34;那么为什么在Extended.Wpf.Toolkit控件中更改了它?在上面的例子中,按钮的AutomationId =&#34; Btn1&#34;在任何地方都没有改变,它工作正常,所以我怀疑工具包正在做一些事情。
是否有解决方案让我的编码ui测试工作?
以防它有帮助,这是我正在测试的窗口的XAML
<Window x:Class="WpfApplication1.ControlsWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApplication1"
mc:Ignorable="d"
Title="ControlsWindow" Height="900" Width="300"
WindowStartupLocation="Manual"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit">
<StackPanel Orientation="Vertical">
<Button Width="75" Height="40"
Canvas.Top="0" Canvas.Left="0" AutomationProperties.AutomationId="Btn1">Click Me</Button>
<Button Width="75" Height="40"
Canvas.Top="0" Canvas.Left="0" AutomationProperties.AutomationId="Btn2">Click Me</Button>
<Button Width="75" Height="40"
Canvas.Top="0" Canvas.Left="0" AutomationProperties.AutomationId="Btn3">Click Me</Button>
<Button Width="75" Height="40"
Canvas.Top="0" Canvas.Left="0" AutomationProperties.AutomationId="Btn4">Click Me</Button>
<ToggleButton Foreground="White" Background="Red"
Canvas.Top="40" Canvas.Left="0" AutomationProperties.AutomationId="Tgl1">Toggle Me</ToggleButton>
<ToggleButton Foreground="White" Background="Red"
Canvas.Top="40" Canvas.Left="0" AutomationProperties.AutomationId="Tgl2">Toggle Me</ToggleButton>
<ToggleButton Foreground="White" Background="Red"
Canvas.Top="40" Canvas.Left="0" AutomationProperties.AutomationId="Tgl3">Toggle Me</ToggleButton>
<ToggleButton Foreground="White" Background="Red"
Canvas.Top="40" Canvas.Left="0" AutomationProperties.AutomationId="Tgl4">Toggle Me</ToggleButton>
<CheckBox BorderBrush="Green" BorderThickness="10"
Canvas.Top="80" Canvas.Left="0" AutomationProperties.AutomationId="Chk1">Check Me</CheckBox>
<RadioButton FontFamily="Algerian" FontSize="24"
Canvas.Top="0" Canvas.Left="80" AutomationProperties.AutomationId="Rad1">Yes</RadioButton>
<RadioButton FontStyle="Italic" FontWeight="Bold"
Canvas.Top="50" Canvas.Left="80" AutomationProperties.AutomationId="Rad2">No</RadioButton>
<CheckBox BorderBrush="Green" BorderThickness="10"
Canvas.Top="80" Canvas.Left="0" AutomationProperties.AutomationId="Chk2">Check Me</CheckBox>
<RadioButton FontFamily="Algerian" FontSize="24"
Canvas.Top="0" Canvas.Left="80" AutomationProperties.AutomationId="Rad3">Yes</RadioButton>
<RadioButton FontStyle="Italic" FontWeight="Bold"
Canvas.Top="50" Canvas.Left="80" AutomationProperties.AutomationId="Rad4">No</RadioButton>
<CheckBox BorderBrush="Green" BorderThickness="10"
Canvas.Top="80" Canvas.Left="0" AutomationProperties.AutomationId="Chk3">Check Me</CheckBox>
<RadioButton FontFamily="Algerian" FontSize="24"
Canvas.Top="0" Canvas.Left="80" AutomationProperties.AutomationId="Rad5">Yes</RadioButton>
<RadioButton FontStyle="Italic" FontWeight="Bold"
Canvas.Top="50" Canvas.Left="80" AutomationProperties.AutomationId="Rad6">No</RadioButton>
<CheckBox BorderBrush="Green" BorderThickness="10"
Canvas.Top="80" Canvas.Left="0" AutomationProperties.AutomationId="Chk4">Check Me</CheckBox>
<RadioButton FontFamily="Algerian" FontSize="24"
Canvas.Top="0" Canvas.Left="80" AutomationProperties.AutomationId="Rad7">Yes</RadioButton>
<RadioButton FontStyle="Italic" FontWeight="Bold"
Canvas.Top="50" Canvas.Left="80" AutomationProperties.AutomationId="Rad8">No</RadioButton>
<xctk:IntegerUpDown AutomationProperties.AutomationId="Nuid1" />
<xctk:IntegerUpDown AutomationProperties.AutomationId="Nuid2" />
<xctk:IntegerUpDown AutomationProperties.AutomationId="Nuid3" />
<xctk:IntegerUpDown AutomationProperties.AutomationId="Nuid4" />
</StackPanel>