2017-02-07 5 views
1

내 UI는 사용자 지정 컨트롤을 사용하여 예/아니요 스위치를 나타냅니다. UI 테스트에서 화면의 컨트롤 반복마다 예 또는 아니요를 탭 할 수 있지만 AutomationID를 쿼리하면 첫 번째 결과가 표시됩니다. 특정 사용자 정의 컨트롤의 하위 버튼에 어떻게 액세스합니까? 내가 탭할 항목은 SwitchLPRrec의 ButtonNo/ButtonYes 및 SwitchTowDolly의 ButtonNo/ButtonYes입니다.Xamarin.UITest 사용자 지정 컨트롤의 자식 하위 요소 동일한 AutomationID가있는 자식 요소

사용자 정의 스위치

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

내가 추가 한 컨테이너가 아닌 자동화 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 ].