dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.03k stars 1.73k forks source link

Picker control does not properly emit `SemanticProperties.Description` as `content-desc` on Android #16282

Open hansmbakker opened 1 year ago

hansmbakker commented 1 year ago

Description

The Semantic Properties are the recommended way in MAUI to add accessibility metadata.

On Android (have not tested on other platforms yet), this does not work consistently across all controls making it harder to make UI tests.

For a Button control, this works correctly. The SemanticProperties.Description XAML is translated to the content-desc field //android.widget.Button[@content-desc="My semantic properties description"] and Appium will interpret that correctly as the accessibility id. The SemanticProperties.Hint XAML is correctly translated to the hint field.

Bug For the Picker control this does not work. The SemanticProperties.Hint XAML attributes is propagated to the resulting Android app but the SemanticProperties.Description is not.

Instead, the SemanticProperties.Description is emitted as the text property of the EditText view that represents the Picker control in Android.

Steps to Reproduce

  1. Create a File > New .NET MAUI App
  2. Add a Button and a Picker like so:
    <Button Text="My button"
        SemanticProperties.Description="This is the semantic properties description for the Button"
        SemanticProperties.Hint="This is the semantic properties hint for the Button" />
    <Picker Title="My picker"
        SemanticProperties.Description="This is the semantic properties description for the Picker"
        SemanticProperties.Hint="This is the semantic properties hint for the Picker">
    <Picker.ItemsSource>
        <x:Array Type="{x:Type x:String}">
            <x:String>A</x:String>
            <x:String>B</x:String>
            <x:String>C</x:String>
        </x:Array>
    </Picker.ItemsSource>
    </Picker>
  3. Inspect the app using Appium with platformName = Android and appium:automationName = UiAutomator2

Expected outcome: the Picker can be found in Appium using the accessibility id which can be set by SemanticProperties.Description in XAML Actual outcome: the SemanticProperties.Description is propagated as the text property of the EditText view in Android

Link to public reproduction project repository

https://github.com/hansmbakker/PickerAccessibilityBugRepro

Version with bug

8.0.0-preview.6.8686

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

Android API level 33

Did you find any workaround?

Use XPath to find an element, which is not recommended.

Relevant log output

No response

hansmbakker commented 1 year ago

Appium Inspector comparison

Button (good)

image

Picker (bad)

image

hansmbakker commented 1 year ago

Adding to this: The Picker is represented by an EditText view on Android in unfocused state. When it is tapped to show its options, it is replaced in-place by a set of different views that do not have an id anymore. This makes it very awkward to use in UI tests.

hansmbakker commented 1 year ago

Related bug https://github.com/dotnet/maui/issues/1186 - this one was reproduced bug closed. I cannot comment there anymore, but probably would be good to have that one reopened

PureWeen commented 1 year ago

@hansmbakker You need to use AutomationId to locate elements

https://github.com/dotnet/maui/issues/8277

We use an AccessibilityDelegate a few places in Android to manage accessibility to work around some bugs in Android so we don't always propagate those to content-desc

ghost commented 1 year ago

Hi @hansmbakker. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

hansmbakker commented 1 year ago

@PureWeen

hansmbakker commented 1 year ago

@PureWeen I saw you added https://github.com/dotnet/docs-maui/issues/1577 - this would be really welcome to have some insight in how to more effectively write UI tests!