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 4.2.0.848062 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"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:d="http://xamarin.com/schemas/2014/forms/design"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             mc:Ignorable="d"
             x:Class="MyApp.Views.AddThingView"
             Title="Add New Thing">

    <ContentPage.ToolbarItems>
        <ToolbarItem Text="Add" Clicked="Add_Thing" />
    </ContentPage.ToolbarItems>

    <ContentPage.Content>
        <StackLayout>

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

        </StackLayout>
    </ContentPage.Content>
</ContentPage>

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"
              [EntryRenderer]
                [FormsEditText] id: "NoResourceEntry-7"
              [LabelRenderer] id: "NoResourceEntry-8" text: "Description"
              [EntryRenderer]
                [FormsEditText] id: "NoResourceEntry-9"
          [Toolbar] id: "toolbar"
            [ActionMenuView]
              [ActionMenuItemView] id: "NoResourceEntry-0" text: "Add"
            [AppCompatTextView] text: "Add New Thing"
            [AppCompatImageButton]
  [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.

Suggestions?

Sign In or Register to comment.