Xamarin UI Tests: AutomationId not getting translated to a Label

fleminggflemingg Member ✭✭
edited December 2019 in Xamarin.Forms

Currently using VS2019 with Xamarin.Forms version and doing a targeted build for Android 9.0. App works great, but testing has been a pain.
Issue right now is that I have some XAML looking like this:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
             Title="Add New Thing">

        <ToolbarItem Text="Add" Clicked="Add_Thing" />


            <Label AutomationId="ThingName" Text="Thing Name" FontSize="24" VerticalOptions="Center"/>
            <Entry Text="{Binding ThingName}" AutomationId="ThingNameEntry" Placeholder="Enter Name Here" VerticalOptions="Center" />

            <Label AutomationId="ThingDescription" Text="Description" FontSize="24" VerticalOptions="Center" />
            <Entry Text="{Binding Description}" AutomationId="ThingDescriptionEntry" Placeholder="Enter Description Here" VerticalOptions="Center" />


My test then looks like this:

public void TestAddThing()
            AppResult[] results = app.WaitForElement(c => c.Marked("Things"));
            app.Screenshot("Welcome screen.");

            Assert.AreEqual(results.Length, 1);

            app.Tap(x => x.Class("ActionMenuItemView").Index(0)); //This navigates to the page for adding "things"
            app.Repl();  //i when I do a "tree" in the repl() loop
            app.EnterText("ThingNameEntry", "Thing 1");
            app.EnterText(c => c.Marked("ThingDescriptionEntry"), "This is our first thing.");


The issue right now is that the app.EnterText(...) methods are not working (they time out and the runner complains it can't find an element marked as "ThingNameEntry" or "ThingDescriptionEntry".
When I do a 'tree' in the repl that the app spins up, I see the following:

[[object CalabashRootView] > DecorView]
  [LinearLayout > FrameLayout]
    [FitWindowsFrameLayout] id: "action_bar_root"
      [ContentFrameLayout > ... > PlatformRenderer] id: "content"
        [NavigationPageRenderer] id: "NoResourceEntry-1"
          [PageContainer] id: "NoResourceEntry-10"
            [PageRenderer > Platform_DefaultRenderer] id: "NoResourceEntry-5"
              [LabelRenderer] id: "NoResourceEntry-6" text: "Thing Name"
                [FormsEditText] id: "NoResourceEntry-7"
              [LabelRenderer] id: "NoResourceEntry-8" text: "Description"
                [FormsEditText] id: "NoResourceEntry-9"
          [Toolbar] id: "toolbar"
              [ActionMenuItemView] id: "NoResourceEntry-0" text: "Add"
            [AppCompatTextView] text: "Add New Thing"
  [View] id: "navigationBarBackground"
  [View] id: "statusBarBackground"

Does ANYONE know why the automationId's are not getting translated into labels?

I will say this is an extremely frustrating acceptance test framework to use. As you can see I wasn't able to pull automationId's off the toolbar item either and had to revert to a relatively ungraceful "x.class(....)" workaround. Hopefully there is a similarly easy workaround for this.


Sign In or Register to comment.