【问题标题】:Xamarin UI test: Read out visible elements that are not shown with Repl tree command (Grid)Xamarin UI 测试:读出未使用 Repl 树命令(网格)显示的可见元素
【发布时间】:2018-11-06 22:21:51
【问题描述】:


我有一个 xaml 页面,由 Grid 元素分割:

<Grid Style="{DynamicResource Key=MainGrid}" BackgroundColor="{DynamicResource Key=White}">
    <Grid.RowDefinitions>
        <RowDefinition Height="20*"></RowDefinition>
        <RowDefinition Height="12*"></RowDefinition>
        <RowDefinition Height="69*"></RowDefinition>
    </Grid.RowDefinitions>
</Grid>

稍后我用两个标签填充第二个原始数据:

<StackLayout Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Spacing="10" Margin="{DynamicResource Key=ContentMargin}">
    <Label Text="Text1" AutomationId="Text1"/>
    <Label Text="Text2" AutomationId="Text2"/>
</StackLayout>

在应用程序的页面中显示两个标签,但我的问题是,测试自动机无法读取第二个文本。
如果我使用 Repl 并输入“树”命令,则根本不会读出第二个元素:

[Platform_DefaultRenderer]
    [LabelRenderer] label: "Text1_Container"
        [FormsTextView] id: "NoResourceEntry-18",  label: "Text1",  text: "Text1"
[Platform_DefaultRenderer]

如果我将第 2 行的高度增加 2%(并减去第 3 行的 2%),则这两个元素对于 UI 测试都是可见的。
为什么会这样?除了更改行高以读出“Text2”的内容外,我可以更改任何内容吗?

我的应用程序使用的是 android 8.1。

【问题讨论】:

    标签: xaml xamarin xamarin.uitest


    【解决方案1】:

    您尝试过哪些查询来访问第二个元素?如果您只需要获取第二个元素的文本,请尝试使用:

    app.Query(c => c.All().Class("FormsTextView").Index(1)).First().Text
    

    即使它对“树”命令不可见,它也应该找到该元素。

    【讨论】:

    • 感谢您的回答。这有很大帮助。我使用了以下内容:“app.Query(c => c.All().Class("FormsTextView")).ToList()”。之后我在返回的列表中执行 Where(...) 以找到正确的元素。
    【解决方案2】:

    在 Android 上,Xamarin.UITest 只能访问当前在屏幕上以及稍远的视图。因此,请尝试使用app.ScrollDown(...) 向下滚动。

    你不会在 iOS 上遇到这个问题。

    【讨论】:

    • 您好,感谢您的回复,但这无济于事。我有固定(高度)的原始数据。它不可滚动。正如我所说,我可以用眼睛看到整个内容,但不能用 tree 命令。
    猜你喜欢
    • 1970-01-01
    • 2019-09-02
    • 1970-01-01
    • 1970-01-01
    • 2017-05-04
    • 1970-01-01
    • 1970-01-01
    • 2016-01-19
    • 1970-01-01
    相关资源
    最近更新 更多