2017-02-07 13 views
1

UIはカスタムコントロールを使用して、yes/noスイッチを表します。 UIテストでは、画面上のコントロールの反復ごとに「はい」または「いいえ」をタップすることができますが、AutomationIDによってクエリを実行すると、最初の結果が得られます。特定のカスタムコントロールの子ボタンにアクセスするにはどうすればよいですか?私がタップする項目は、SwitchLPRrecのButtonNo/ButtonYesとSwitchTowDollyのButtonNo/ButtonYesです。Xamarin.UITestカスタムコントロールの子要素が同じAutomationIDを持つ子要素をタップ

カスタムスクリーンのREPLカスタムコントロールを点滅

enter image description here

答えて

1

がコンテナではなく、私が追加したオートメーション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); 
     } 

} 

を切り替えますコントロールの。

> >>> 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 ]. 
関連する問題