question

Shr-2223 avatar image
0 Votes"
Shr-2223 asked LeonLu-MSFT edited

Unable to assign Accessibility using Automation properties to Labels defined inside flex layout

I need to locate my Android elements written in Xamarin forms on Appium for automation testing. I have the following structure of code:

  <ListView.ItemTemplate>
                     <DataTemplate>
                         <ViewCell>
                             <FlexLayout BackgroundColor="{Binding IsConnectable, Converter={StaticResource isConnectableConverter}}" Direction="Row" JustifyContent="Start" AlignItems="Center">
    
                                 <FlexLayout FlexLayout.Basis="80" Direction="Column" AlignItems="Center" JustifyContent="Center" Margin="0,0,0,0"  AutomationProperties.IsInAccessibleTree="True" AutomationProperties.Name="DeviceInfoGroup1">
                                     <Image FlexLayout.AlignSelf="Center" Source="{Binding Rssi, Converter={StaticResource rssiImageConverter}}" HeightRequest="64" Margin="0,0,0,0" AutomationProperties.IsInAccessibleTree="True" AutomationProperties.Name="BatteryImage"/>
                                     <Label HorizontalTextAlignment="Center" Text="{Binding Rssi.value}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small"/>
                                 </FlexLayout>
    
                                 <FlexLayout FlexLayout.Basis="170" Direction="Column" AlignItems="Start" JustifyContent="SpaceEvenly" Margin="1,0,0,0" AutomationProperties.IsInAccessibleTree="True" AutomationProperties.Name="DeviceInfoGroup2">
                                     <Label HorizontalTextAlignment="Start" Text="{Binding LocalName}" LineBreakMode="NoWrap" Style="{DynamicResource TitleStyle}" FontAttributes="Bold" FontSize="24"/>
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.SystemId, Converter={StaticResource systemIdConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource SubtitleStyle}" FontAttributes="Bold" FontSize="20"/>
                                     <StackLayout Orientation="Horizontal" HorizontalOptions="StartAndExpand" Spacing="20"  AutomationProperties.IsInAccessibleTree="True" AutomationProperties.Name="DeviceInfoGroup2a">
                                         <Label HorizontalTextAlignment="Start" Text="{Binding Address, Converter={StaticResource bdaddrConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource SubtitleStyle}" FontSize="Small"/>
                                         <Label HorizontalTextAlignment="End" Text="{Binding Path=ManufacturingData.FirmwareBuildNumber, StringFormat='{0}'}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small"/>
                                     </StackLayout>
                                 </FlexLayout>
    
                                 <FlexLayout FlexLayout.Basis="150" Direction="Column" AlignItems="Start" JustifyContent="Start" IsVisible="{OnIdiom Tablet=true, Phone=false}" Margin="1,0,0,0" AutomationProperties.IsInAccessibleTree="True" AutomationProperties.Name="DeviceInfoGroup3">
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.DeviceStatus.InsEicState, Converter={StaticResource insEicStateConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small"/>
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.DeviceStatus.StimulationState, Converter={StaticResource stimulationStateConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small" />
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.DeviceStatus.StimulationProgramId, Converter={StaticResource stimulationProgramIdConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small" />
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData, Converter={StaticResource scheduleConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small" />
                                 </FlexLayout>
    
                                 <FlexLayout FlexLayout.Basis="150" Direction="Column" AlignItems="Start" JustifyContent="Start" IsVisible="{OnIdiom Tablet=true, Phone=false}" Margin="1,0,0,0" AutomationProperties.IsInAccessibleTree="True" AutomationProperties.Name="DeviceSystemInfo4">
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.DeviceStatus.PostureState, Converter={StaticResource postureStateConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small" />
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.DeviceStatus.SessionState, Converter={StaticResource sessionStateConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small" />
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.DeviceStatus.LowPowerState, Converter={StaticResource lowPowerStateConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small" />
                                     <Label HorizontalTextAlignment="Start" Text="{Binding Path=ManufacturingData.DeviceStatus.LowBatteryMode, Converter={StaticResource lowBatteryModeConverter}}" LineBreakMode="NoWrap" Style="{DynamicResource ListItemTextStyle}" FontSize="Small" />
                                 </FlexLayout>
    
    
                             </FlexLayout>
                         </ViewCell>
                     </DataTemplate>
                 </ListView.ItemTemplate>



I am able to add the Automation properties to the layout and image items but they are not being detected in Appium when I add the properties to label items. Could someone help me understand how to fix this issue? Thank you

dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

LeonLu-MSFT avatar image
0 Votes"
LeonLu-MSFT answered LeonLu-MSFT edited

Hello,​


This issue was reported on Github page.

But I found a workaround to fix this issue. Please move to use CollectionView, then make an ItemTemplate, setting the AutomationId on one of the child controls inside the template, rather than the cell container. create a Label 's custom renderer, use the AutomationId in OnElementPropertyChanged, for more details, please check following link.
https://github.com/xamarin/Xamarin.Forms/issues/10492#issuecomment-869952873

Best Regards,

Leon Lu



If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


· 4
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Shr-2223 May I know if you have got any chance to check my answer? I am glad to help if you have any other questions

0 Votes 0 ·

Thank you for your reply. I could not get a chance to try it since I am on vacation. Will let you know in a few days.

0 Votes 0 ·

Fine, waiting for your update.

0 Votes 0 ·

@Shr-2223 I have not heard from you for a couple of days. Please let me know if there is anything that I can help here

0 Votes 0 ·