【问题标题】:Get Appium automation element in runtime在运行时获取 Appium 自动化元素
【发布时间】:2020-05-19 05:57:57
【问题描述】:

我需要为控制创建自动化系统级测试。 控件由样式设置,并具有 ListView 和单独的 ListViewItem 模板。 我的目标是从这个ListViewItem 的标题中获取文本。 这是我在 XAML 中的内容(代码简化)

<Style>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate>
                <Border>
                    <Grid>
                        <ScrollViewer x:Name="ScrollViewer">
                            <ScrollViewer.TopHeader>
                                <StackPanel>
                                    <ListView ItemsSource="{TemplateBinding SomeSource}"
                                              ItemTemplate="{StaticResource MyTemplate}">
                                        <ListView.ItemsPanel>
                                            <ItemsPanelTemplate>
                                                <ItemsStackPanel/>
                                            </ItemsPanelTemplate>
                                        </ListView.ItemsPanel>
                                    </ListView>
                                </StackPanel>
                            </ScrollViewer.TopHeader>
                        </ScrollViewer>
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

ListViewItem 的模板类似于:

<DataTemplate>
    <Grid>
        <Grid>
            <TextBlock x:Name="TextName"
                       AutomationProperties.AutomationId="{Binding SomeId}"
                       Text="{x:Bind SomeText}"/>
        </Grid>
    </Grid>
</DataTemplate>

当然ListViewItems 是在运行时自动生成的。它们被绑定到相应的属性并获得所需的模板。

但在测试中我无论如何都无法到达我的TextBlockByIdFindElementById 等等)。 我可以先按类查找ListView (FindElementByClassName),然后按类查找ListViewItems,然后按类查找TextBlock,但我认为这不是正确的方法。因为将来控制结构可能会发生变化,并且支持测试会更加困难。

控件也有 AutomationPeer 作为网格。

那么你有什么想法为什么我不能通过他们的AutomationId 得到我的简单TextBlock 甚至ListViewItems?

【问题讨论】:

    标签: c# uwp automated-tests appium appium-desktop


    【解决方案1】:

    问题已通过为 conrtol 创建自定义自动化对等方来解决。控件继承 ListView(在问题描述中不清楚)。因此,自动化 id 继承的 listview 控件中的 listview 存在问题。

    在显示元素之后但在 WinAppDriver 查找元素之前添加 Thread.Sleep()Task.Delay() 也很有帮助。 看起来测试环境需要更多时间来绑定和查找元素。

    【讨论】:

      猜你喜欢
      • 2020-01-14
      • 2019-10-05
      • 2021-10-26
      • 2016-01-19
      • 2015-08-25
      • 1970-01-01
      • 2019-11-03
      • 2019-11-18
      • 2019-01-16
      相关资源
      最近更新 更多