xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.62k stars 1.87k forks source link

XAML AutomationID ignored by REPL tool and other queries on *Cell components #4731

Open ahanag22 opened 5 years ago

ahanag22 commented 5 years ago

Description

@PureWeen notes: This is also broken with ImageCell and I'm guessing it is broken with the other Cell's as well so when this is resolved make sure to test all the *Cell components. If you look at Issue4597 you'll see the complexity required to test the ImageCell. Once this is fixed please cleanup Issue4597

I'm using Forms app. In TableView, EntryCell's AutomationId in XAML pages is being ignored, as a result tests are not being able to use AutomationID with XAML pages.

XAML for the settings page:

<TableView Intent="Settings">
        <TableRoot>
            <TableSection Title="First Section">
                <TextCell Text="TextCell" Detail="TextCell Detail" />
                <EntryCell Label="Entry Label" Text="EntryCell Text" AutomationId="ENTRY_CELL_TEXT_1" />
                <SwitchCell Text="SwitchCell Text" />
                <ImageCell Text="ImageCell Text" Detail="ImageCell Detail" ImageSource="XamarinLogo.png" />
            </TableSection>
            <TableSection Title="Second Section">
                <TextCell Text="TextCell" Detail="TextCell Detail" />
                <EntryCell Label="Entry Label" Text="EntryCell Text" AutomationId="ENTRY_CELL_TEXT_2"/>
                <SwitchCell Text="SwitchCell Text" />
                <ImageCell Text="ImageCell Text" Detail="ImageCell Detail" ImageSource="XamarinLogo.png" />
            </TableSection>
        </TableRoot>
    </TableView>

However, tests are not being able to use AutomationIDs defined in the xaml page, Repl tree command fails to display EntryCell's AutomationId

[UITableViewSectionElement] id: "First Section" [UIAccessibilityElementMockView] label: "First Section" [UITableViewCellAccessibilityElement] [UITableTextAccessibilityElement] label: "TextCell, TextCell Detail" [UITableViewCellAccessibilityElement] [UITableTextAccessibilityElement] label: "Entry Label" [UIAccessibilityElementMockView] text: "EntryCell Text" [UIAccessibilityTextFieldElement] text: "EntryCell Text" [UITableViewCellAccessibilityElement] text: "0" [UITableTextAccessibilityElement] label: "SwitchCell Text", text: "0" [UIAccessibilityElementMockView] label: "SwitchCell Text", text: "0" [UITableViewCellAccessibilityElement] [UITableTextAccessibilityElement] label: "ImageCell Text, ImageCell Detail" [UITableViewSectionElement] id: "Second Section" [UIAccessibilityElementMockView] label: "Second Section" [UITableViewCellAccessibilityElement] [UITableTextAccessibilityElement] label: "TextCell, TextCell Detail" [UITableViewCellAccessibilityElement] [UITableTextAccessibilityElement] label: "Entry Label" [UIAccessibilityElementMockView] text: "EntryCell Text" [UIAccessibilityTextFieldElement] text: "EntryCell Text" [UITableViewCellAccessibilityElement] text: "0" [UITableTextAccessibilityElement] label: "SwitchCell Text", text: "0" [UIAccessibilityElementMockView] label: "SwitchCell Text", text: "0" [UITableViewCellAccessibilityElement] [UITableTextAccessibilityElement] label: "ImageCell Text, ImageCell Detail" [UITableViewCellAccessibilityElement] [UIAccessibilityElementMockView] label: "Tap this cell."

Steps to Reproduce

  1. Set automation id of an EntryCell.Label in XAML
  2. Create a simple Xamarin.UITests
  3. Start REPL; run the tree command

Expected Behavior

Automation id of EntryCell.Label should be detected

Actual Behavior

AutomationID is ignored by REPL

Basic Information

-Affected Devices: I can reproduce this issue on all the iOS 12 simulators (I don't have any iOS physical devices).

Screenshots

screen shot 2018-12-13 at 3 04 40 pm screen shot 2018-12-13 at 3 18 49 pm

Reproduction Link

I can reproduce the issue using this sample:

https://github.com/xamarin/xamarin-forms-samples/tree/master/UserInterface/TableView

King-of-Spades commented 5 years ago

I'm following this issue as well for updates or if any other info is needed.

arichar1990 commented 5 years ago

Has there been any progress on this issue? I'm experiencing issues with the tap commands on iOS simulators. I can't target specific UI elements without AutomationIds set in XAML

james1301 commented 5 years ago

Is anybody looking at this? This is stopping us doing any UI Testing.

theonlyroboboro commented 5 years ago

Has there been any progress on this issue?

husseinmohkhalil commented 5 years ago

Any updates on this issue?

SittenSpynne commented 5 years ago

This is affecting me too.

ouardia-y commented 4 years ago

I tried the following and I see the automation Id appear in the REPL tool. However, it cannot tap on the toggle because the automation Id is being set on the whole row and not the toggle switch.

I created a class CustomSwitchCell that inherits the custom control from the default Xamarin Forms SwitchCell.

public class CustomSwitchCell : SwitchCell
    {
        public static readonly BindableProperty AutomationIdBindableProperty = BindableProperty.Create(
                propertyName: "AutomationIdBindable",
                returnType: typeof(string),
                declaringType: typeof(SwitchCell),
                defaultValue: null);

        public string AutomationIdBindable
        {
            get
            {
                return GetValue(AutomationIdBindableProperty) as string;
            }
            set
            {
                SetValue(AutomationIdBindableProperty, value);
            }
        }
    } 

Then, I created a Custom Renderer in my iOS project that looks like the following:

[assembly: ExportRenderer(typeof(CustomSwitchCell), typeof(YourProject.LocationOfFile.CustomSwitchCellRenderer))]
namespace YourProject.LocationOfFile
{
    public class CustomSwitchCellRenderer : SwitchCellRenderer
    {
        public override UITableViewCell GetCell(Cell item, UITableViewCell reusableCell, UITableView tv)
        {
            var cell = base.GetCell(item, reusableCell, tv);

            var customSwitchCell = item as CustomSwitchCell;
            if (customSwitchCell != null && customSwitchCell.AutomationIdBindable != null)
            {
                cell.AccessibilityIdentifier = customSwitchCell.AutomationIdBindable;
            }

            return cell;
        }
    }
}
james1301 commented 4 years ago

@PureWeen how come there hasn't been anymore progress on this in over a year?

shaungreenfield commented 4 years ago

We rebuilt using the latest Xamarin (4.4) and also have this issue. What's very strange is back when we started to look at automation we had built with 3.4 and the automation was working.

We rebuilt with 3.4 and a few updates to our code and it STOPPED working. What we've noticed is that if you assign the automation ID via code - that does show up but any automation ID assigned via the xaml does not.

nicoteitel commented 4 years ago

Any news on this bug? I'm having a similar issue but in a CollectionView ONLY ON ANDROID. I have a ContentView with a Grid, and inside that grid, there is a CollectionView. AutomationID for CollectionView is ignored, if on top of it, I add a StackLayout with an AutomationID, I can see it, but I cannot see the AutomationID for the CollectionView.

i.e:

<StackLayout AutomationId="StackOnTopOfCollectionView" >
                    <CollectionView Grid.Row="0" x:Name="ActivityFeedView" AutomationID="ActivityFeed" Scrolled="ActivityFeedView_Scrolled" ItemsSource="{Binding Items}" Style="{StaticResource CommentsListListView}" IsVisible="{Binding Items, Converter={StaticResource HasItemsConverter}}">
                        <CollectionView.Effects>
                            <Local:CollectionView_AlwaysBounceVertical_Effect />
                            <Local:CollectionView_NoScrollIndicators_Effect />
                        </CollectionView.Effects>
                        <CollectionView.ItemsLayout>
                            <LinearItemsLayout Orientation="Vertical" ItemSpacing="10"/>
                        </CollectionView.ItemsLayout>
                        <CollectionView.ItemTemplate>
                            <!-- Activity Feeds List -->
                            <DataTemplate>
                                <ContentView Style="{StaticResource CommentsViewCell}" AutomationId="{x:Static Automation:TestIdentifier.PUNCHITEMEDITPAGE_COMMENTS_LIST_CELL}">
                                    <Local:CommentsCell OpenMenuCommand="{Binding Source={x:Reference PunchItemCommentsList}, Path=BindingContext.OpenMenuForCommentCommand}"
                                                        OnShowFile="CommentCell_ShowFile" OnShowDrawing="CommentCell_ShowDrawing" /> 
                                </ContentView>
                            </DataTemplate>
                        </CollectionView.ItemTemplate>
                    </CollectionView>
                </StackLayout>

In this case, StackOnTopOfCollectionView is visible with REPL but ActivityFeed is not.

james1301 commented 4 years ago

@samhouts or @PureWeen? Feels like this just keeps getting moved on and not done? Can we commit to doing this ASAP please. V5 feels far too far away,

Welchen commented 3 years ago

Is there any update on this? We just ran into this and currently keeping us from writing tests.