phil pastor
phil pastor

Reputation: 53

Xamarin UITest cannot EnterText

UITest newbie here, and right out of the gate I hit a wall... My Android form has a custom control "AccessCodeEntry" which inherits from Xamarin.Forms.Entry. XAML basically looks like this...

<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>

This renders as: Access Code label and textbox

Following is the tree view for my form:

>>> 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"
>>>

When I query for this control, whether by Text, Class, etc... it always returns coordinates in the center of this area. Which means that I cannot tap inside the textbox, and the soft keyboard never shows up. I always get a timeout exception waiting for the keyboard when I try to EnterText. Here is a sample query & result:

>>> 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")
>>>

Here are other queries I have tried, and I basically receive the same coordinates and error:

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

I do have the emulator set to use a soft keyboard. Any suggestions how to do this? Thanks!

Upvotes: 3

Views: 2232

Answers (1)

matisse
matisse

Reputation: 133

It appears that you are querying for for the label at the top of your custom control, rather than the entry itself. You should be able to change your query to look for the entry directly:

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

Or you could grab the sibling of your label with:

app.EnterText(x => x.Text("Access Code:").Parent(0).Sibling(), "ABC12");

Upvotes: 3

Related Questions