Xamarin UITest 无法输入文本
Xamarin UITest cannot EnterText
这里是 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"
>>>
当我查询此控件时,无论是通过文本、Class 等...它总是 returns 坐标在此区域的中心。这意味着我无法在文本框内点击,并且软键盘永远不会出现。当我尝试 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");
这里是 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"
>>>
当我查询此控件时,无论是通过文本、Class 等...它总是 returns 坐标在此区域的中心。这意味着我无法在文本框内点击,并且软键盘永远不会出现。当我尝试 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");