Xamarin UITest无法输入文字
问题描述:
UITest新手在这里,并且走出大门我碰壁了......我的Android窗体有一个自定义控件“AccessCodeEntry”,它继承自Xamarin.Forms.Entry。 XAML基本上看起来像这样...Xamarin UITest无法输入文字
<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"
>>>
当我查询这种控制,无论是文本,类别等......它总是返回该区域中心的坐标。这意味着我无法在文本框内敲击,并且软键盘从不显示。当我尝试使用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")
我有模拟器设置为使用软键盘。任何建议如何做到这一点? 谢谢!
答
看起来您正在查询自定义控件顶部的标签,而不是条目本身。你应该能够改变你的查询,寻找直接的条目:
app.EnterText(x => x.Class("EntryEditText"), "ABC12");
或者你可以抓住你的标签与兄弟:
app.EnterText(x => x.Text("Access Code:").Parent(0).Sibling(), "ABC12");
+0
谢谢,@matisse ....告诉你我是一个新手:) –
这将是有益的,包括你想查询目前。如果你在这里打开REPL('app.Repl()')并包含树视图(只需在REPL中键入'tree'),这也会很有帮助。 – matisse
谢谢,@matisse ...我用数据更新了我原来的问题。 –