1

我的 UI 使用自定义控件来表示是/否开关。在 UI 测试中,我希望能够为屏幕上控件的每次迭代点击是或否,但通过 AutomationID 查询会获取第一个结果。如何访问特定自定义控件的子按钮?我要点击的项目是 SwitchLPRrec 的 ButtonNo/ButtonYes 和 SwitchTowDolly 的 ButtonNo/ButtonYes。

自定义开关

public RC_Switch_YesNo()
{

        try
        {
            this.HorizontalOptions = LayoutOptions.Center;
            this.VerticalOptions = LayoutOptions.Center;

            negative = new Button();
            negative.Text = "No";
            negative.AutomationId = "ButtonNo";
            negative.Style = AppStyling.Style_Button_Switch;
            negative.Clicked += (o, s) => OnSelectedItemChanged(this, ItemSelected, (int)Enums_RecoveryConnect.SelectionStatus.SelectionFalse);

            positive = new Button();
            positive.Text = "Yes";
            positive.AutomationId = "ButtonYes";
            positive.Style = AppStyling.Style_Button_Switch;
            positive.Clicked += (o, s) => OnSelectedItemChanged(this, ItemSelected, (int)Enums_RecoveryConnect.SelectionStatus.SelectionTrue);               

            if(Device.Idiom == TargetIdiom.Tablet)
            {
                negative.HeightRequest = (int)AppStyling.TabletEntry.TabletHeight; 
                positive.HeightRequest = (int)AppStyling.TabletEntry.TabletHeight;
                negative.FontSize = (int)AppStyling.TabletEntry.TabletEntryTextSize;
                positive.FontSize = (int)AppStyling.TabletEntry.TabletEntryTextSize;
            }

            this.Children.Add(negative, 0,0);
            this.Children.Add(positive, 1,0);
        }
        catch(System.Exception ex)
        {
           Helpers.Helper_ErrorHandling.SendErrorToServer(ex);
        }

}

屏幕的 REPL

在此处输入图像描述

4

1 回答 1

1

闪烁自定义控件暴露了容器而不是我添加的自动化 ID 是控件的实际子项。

> >>> app.Flash(e => e.Marked("SwitchLPRrec").Child()) Flashing query for Marked("SwitchLPRrec").Child() gave 2 results. [
>     [0] {
>         Id => null,
>         Description => "md5da774f1c80869349b7bd94a8742a495b.ListButtonRenderer{e95cedd
> V.E...... ........ 0,0-688,192}",
>         Rect => {
>             Width => 688,
>             Height => 192,
>             X => 20,
>             Y => 1501,
>             CenterX => 364,
>             CenterY => 1597
>         },
>         Label => "ButtonNo_Container",
>         Text => null,
>         Class => "md5da774f1c80869349b7bd94a8742a495b.ListButtonRenderer",
>         Enabled => true
>     },
>     [1] {
>         Id => null,
>         Description => "md5da774f1c80869349b7bd94a8742a495b.ListButtonRenderer{568fc95
> V.E...... ........ 712,0-1400,192}",
>         Rect => {
>             Width => 688,
>             Height => 192,
>             X => 732,
>             Y => 1501,
>             CenterX => 1076,
>             CenterY => 1597
>         },
>         Label => "ButtonYes_Container",
>         Text => null,
>         Class => "md5da774f1c80869349b7bd94a8742a495b.ListButtonRenderer",
>         Enabled => true
>     } ]

这使得答案非常明显。

>>> app.Tap(e => e.Marked("SwitchLPRrec").Child().Marked("ButtonNo_Container"))
Using element matching Marked("SwitchLPRrec").Child().Marked("ButtonNo_Container").
Tapping coordinates [ 364, 1597 ].
于 2017-02-07T20:06:13.080 回答