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>
这呈现为: Access Code label and textbox
以下是我的表单的树视图:
>>> 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"
>>>
当我查询此控件时,无论是通过Text,Class等...它总是返回该区域中心的坐标。这意味着我无法点击文本框内部,软键盘也不会出现。当我尝试使用EnterText时,我总是会遇到等待键盘的超时异常。这是一个示例查询&amp;结果:
>>> 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")
我确实将模拟器设置为使用软键盘。有什么建议怎么做? 谢谢!
答案 0 :(得分:2)
您似乎在查询自定义控件顶部的标签,而不是条目本身。您应该能够更改查询以直接查找条目:
app.EnterText(x => x.Class("EntryEditText"), "ABC12");
或者您可以通过以下方式获取标签的兄弟:
app.EnterText(x => x.Text("Access Code:").Parent(0).Sibling(), "ABC12");