【发布时间】:2021-10-25 18:00:20
【问题描述】:
我正在尝试通过自动化测试访问自定义提示对话框的 Type 属性。所以类型的元素(文本框或文本块)被折叠了,因为没有人需要看到它,我只需要它在自动化方面进行逻辑处理。
我不明白为什么尽管它在树中可用,但无法找到它。或者还有其他为什么要获得这样的访问权限?
XAML:
<controls:PromptDialog ...
AutomationProperties.AutomationId="PromptView"
d:DataContext="{d:DesignInstance Type=viewModels:PromptViewModel}">
<Grid Margin="{StaticResource MarginThickness}">
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="{StaticResource Gutter}" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!--Prompt-->
<Grid Grid.Row="0"
Visibility="{Binding IsShowingPrompt, Converter={StaticResource BooleanToVisibilityConverter}}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="4" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="{StaticResource Gutter}" />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<!--Image-->
<ContentControl Grid.Row="0"
Grid.Column="0"
Content="{Binding}">
<ContentControl.Resources>
<DataTemplate DataType="{x:Type viewModels:PromptViewModel}">
<Image Name="Image" />
//displaying image per type
</ContentControl.Resources>
</ContentControl>
<ScrollViewer Grid.Row="0"
Grid.Column="2"
Focusable="False"
VerticalScrollBarVisibility="Auto"
HorizontalScrollBarVisibility="Disabled"
MaxHeight="400">
<StackPanel>
<TextBlock behaviors:TextBoxHyperlinkBehavior.Text="{Binding Text}"
TextWrapping="Wrap"
Focusable="False"
VerticalAlignment="Center"
HorizontalAlignment="Left"
FontFamily="{Binding Font.Name}"
Foreground="{Binding FontColor}"
AutomationProperties.AutomationId="PrompView_Text" />
<TextBox Visibility="Collapsed"
Text="{Binding Type}"
AutomationProperties.AutomationId="PromptView_Type" />
</StackPanel>
</ScrollViewer>
<!--Commands-->
<UniformGrid Grid.Row="2" Rows="1" HorizontalAlignment="Right">
// buttons
</UniformGrid>
</Grid>
Appium:
public IVisualElement Type => _appiumSession.CreateVisualAppiumElement("PromptView_Type");
或者
public AppiumWebElement Type => _appiumSession.FindElementByAccessibilityId("PromptView_Type");
错误:
OpenQA.Selenium.WebDriverTimeoutException : Timed out after 10 seconds
---- OpenQA.Selenium.WebDriverException : An element could not be located on the page using the given search parameters.
高度赞赏任何指针,
谢谢
【问题讨论】:
-
折叠的 ui 片段不在可视化树中。它们没有被渲染。
-
wpf 中有逻辑树和可视树。折叠的 uielement 在逻辑树中但不在可视树中。
-
@Andy 有什么方法可以访问逻辑元素吗?
-
您可以遍历逻辑树,但您应该首先了解它是什么。谷歌并仔细阅读 msdn 文档。事情是这样的。为什么不渲染需要测试的 uielement?这对我来说没有多大意义。
-
该类型对最终用户没有用,因此无需显示它,信息以提示图像(错误、警告等)表示。但我需要它进行测试。我认为它会像 PHP 隐藏标签一样。我正在搜索和阅读与这个问题并行的文档,也许我可以节省一些时间。无论如何谢谢:)
标签: wpf testing automation appium