2017-02-07 44 views
1

我的用戶界面使用自定義控件來表示是/否開關。在UI測試中,我希望能夠在屏幕上控制每次迭代時點擊是或否,但由AutomationID查詢抓取第一個結果。我如何訪問特定自定義控件的子按鈕?我想要點擊的項目是SwitchLPRrec的ButtonNo/ButtonYes和SwitchTowDolly的ButtonNo/ButtonYes。Xamarin.UITest點擊自定義控件的子元素具有相同的自動化ID

自定義開關

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屏幕

enter image description here

回答

1

閃爍暴露,我已經添加的容器,而不是自動化IDS是實際的孩子自定義控件的控制。

> >>> 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 ]. 
相關問題