C# 获取Windows Phone编码UI中矩形的填充颜色
我正在为一个简单的应用程序编写一些编码的UI测试,似乎无法获得查找矩形对象的代码。在特定情况下,矩形的颜色根据填充颜色显示两个字符串是否匹配 当尝试使用编码的UI测试生成器查找矩形时,将查找父对象而不是矩形。我还看到,当我手动搜索矩形时,代码返回无法找到矩形 下面是我尝试测试的页面的XAML:C# 获取Windows Phone编码UI中矩形的填充颜色,c#,xaml,windows-phone-8,coded-ui-tests,C#,Xaml,Windows Phone 8,Coded Ui Tests,我正在为一个简单的应用程序编写一些编码的UI测试,似乎无法获得查找矩形对象的代码。在特定情况下,矩形的颜色根据填充颜色显示两个字符串是否匹配 当尝试使用编码的UI测试生成器查找矩形时,将查找父对象而不是矩形。我还看到,当我手动搜索矩形时,代码返回无法找到矩形 下面是我尝试测试的页面的XAML: <Page x:Class="TestApp.ButtonTester" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentati
<Page
x:Class="TestApp.ButtonTester"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TestApp"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name="LayoutRoot">
<Grid.ChildrenTransitions>
<TransitionCollection>
<EntranceThemeTransition/>
</TransitionCollection>
</Grid.ChildrenTransitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!-- Title Panel -->
<StackPanel Grid.Row="0" Margin="19,0,0,0">
<TextBlock Text="{StaticResource AppName}" Style="{ThemeResource TitleTextBlockStyle}" Margin="0,12,0,0"/>
<TextBlock Name="pageTitle" Text="Button Tester" Margin="0,-6.5,0,26.5" Style="{ThemeResource HeaderTextBlockStyle}" CharacterSpacing="{ThemeResource PivotHeaderItemCharacterSpacing}"/>
</StackPanel>
<!--TODO: Content should be placed within the following grid-->
<Grid Grid.Row="1" x:Name="ContentRoot" Margin="19,9.5,19,0">
<StackPanel Name="buttonValidator">
<TextBlock Name="verifyText" Text="Hi" HorizontalAlignment="Center" Style="{StaticResource LargeText}"/>
<Button Name="changeText" Content="Change Text" HorizontalAlignment="Center" Click="changeText_Click"/>
<TextBox Name="guessText" Text="Enter Text From Above" TextAlignment="Center" GotFocus="guessText_GotFocus" KeyDown="guessText_KeyDown"/>
<Button Name="verifyMatch" Content="Verify" HorizontalAlignment="Center" Click="verifyMatch_Click"/>
<Rectangle Name="matchAlert" Height="50" Width="50" Fill="Black" HorizontalAlignment="Center"/>
</StackPanel>
</Grid>
</Grid>
我还看到测试生成器无法检测矩形,即使它被用作控件
我还研究了Rectangle类和Button类,它们的继承链中的第一个常见链接是Windows.UI.Xaml.FrameworkElement。我不知道编码的UI能够检测到什么类型的项目,以知道这是否是问题的原因
[TestMethod]
public void TestVerifyIncorrect()
{
UITestControl verifyMatch = new UITestControl(myApp);
verifyMatch.TechnologyName = "UIA";
verifyMatch.SearchProperties.Add("ControlType", "Button");
verifyMatch.SearchProperties.Add("AutomationId", "verifyMatch");
Gesture.Tap(verifyMatch);
UITestControl matchAlert = new UITestControl(myApp);
matchAlert.TechnologyName = "UIA";
matchAlert.SearchProperties.Add("ControlType", "Rectangle");
matchAlert.SearchProperties.Add("AutomationId", "matchAlert");
var fillColor = matchAlert.GetProperty("Fill");
}