我的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
答案 0 :(得分: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 ].