3

UITest 新手在这里,一出门我就碰壁了……我的 Android 表单有一个自定义控件“AccessCodeEntry”,它继承自 Xamarin.Forms.Entry。XAML 基本上看起来像这样......

<Label Grid.Row="0" Grid.Column="0" Text="{Translate AccessCodeLabel}" InputTransparent="false" HorizontalOptions="LayoutOptions.Center" VerticalOptions="LayoutOptions.CenterAndExpand"/>
<ContentView Grid.Row="1" Grid.Column="0">
    <local:AccessCodeEntry
        x:Name="AccessCodeEntry" 
        WidthRequest="215"
        HeightRequest="80"
        Text="{Binding AccessCode}"  
        Placeholder=" * * * * *"
        BackgroundColor = "White"
        HorizontalOptions = "LayoutOptions.Center"/>
</ContentView>

这呈现为: 访问代码标签和文本框

以下是我的表单的树视图:

>>> tree
[[object CalabashRootView] > PhoneWindow$DecorView]
  [ActionBarOverlayLayout] id: "action_bar_overlay_layout"
    [FrameLayout > ... > RendererFactory_DefaultRenderer] id: "content"
      [RendererFactory_DefaultRenderer > RendererFactory_DefaultRenderer]
        [LabelRenderer]
          [FormsTextView] text: "Access Code:"
        [RendererFactory_DefaultRenderer > ... > EntryEditText]
      [RendererFactory_DefaultRenderer > CustomButtonRenderer]
        [Button] text: "Load Access Code"
      [RendererFactory_DefaultRenderer > ... > LabelRenderer]
        [FormsTextView] text: "Patient ID:"
    [ActionBarContainer] id: "action_bar_container"
      [ActionBarView] id: "action_bar"
        [LinearLayout > ActionBarView$HomeView] label: "Navigate up"
          [ImageView] id: "up"
          [ImageView] id: "home"
>>>

当我查询此控件时,无论是通过文本、类等...它始终返回该区域中心的坐标。这意味着我无法在文本框内点击,并且软键盘永远不会出现。当我尝试 EnterText 时,我总是遇到等待键盘的超时异常。这是一个示例查询和结果:

>>> app.EnterText("Access Code:", "ABC12")
Using element matching Marked("Access Code:").
Tapping coordinates [ 238, 188 ].
Error while performing EnterText(Marked("Access Code:"), "ABC12")
Exception: System.TimeoutException: Timed out waiting for keyboard to be shown.
   at Xamarin.UITest.Shared.WaitForHelper.WaitFor(Func`1 predicate, String timeoutMessage, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout)
   at Xamarin.UITest.Android.AndroidApp.<EnterText>c__AnonStorey6.<>m__0()
   at Xamarin.UITest.Utils.ErrorReporting.With(Action func, Object[] args, String memberName)
Exception: Error while performing EnterText(Marked("Access Code:"), "ABC12")
>>>

这是我尝试过的其他查询,我基本上收到相同的坐标和错误:

app.EnterText(c => c.Text("Access Code:"), "ABC12")
app.EnterText(c => c.Class("FormsTextView"), "ABC12")

我确实将模拟器设置为使用软键盘。任何建议如何做到这一点?谢谢!

4

1 回答 1

3

您似乎正在查询自定义控件顶部的标签,而不是条目本身。您应该能够更改查询以直接查找条目:

app.EnterText(x => x.Class("EntryEditText"), "ABC12");

或者您可以通过以下方式获取标签的兄弟姐妹:

app.EnterText(x => x.Text("Access Code:").Parent(0).Sibling(), "ABC12");
于 2017-07-24T22:32:49.960 回答