diff --git a/src/Controls/tests/TestCases.HostApp/Issues/MauiDoneAccessoryButton.cs b/src/Controls/tests/TestCases.HostApp/Issues/MauiDoneAccessoryButton.cs new file mode 100644 index 000000000000..33e006425e86 --- /dev/null +++ b/src/Controls/tests/TestCases.HostApp/Issues/MauiDoneAccessoryButton.cs @@ -0,0 +1,47 @@ +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 32825, "MauiDoneAccessoryView DoneButton should be accessible for UI testing", PlatformAffected.iOS)] +public class MauiDoneAccessoryButton : TestContentPage +{ + protected override void Init() + { + var entry = new Entry + { + AutomationId = "NumericEntry", + Keyboard = Keyboard.Numeric, + Placeholder = "Tap here to show numeric keyboard with Done button" + }; + + var label = new Label + { + AutomationId = "ResultLabel", + Text = "Waiting for entry to be focused" + }; + + entry.Focused += (s, e) => + { + label.Text = "Entry focused - Done button should be accessible"; + }; + + entry.Completed += (s, e) => + { + label.Text = "Entry completed - Done button was tapped"; + }; + + Content = new VerticalStackLayout + { + Padding = new Thickness(20), + Spacing = 10, + Children = + { + new Label + { + Text = "This test verifies that the Done button on numeric keyboards has an accessibility identifier for UI testing.", + Margin = new Thickness(0, 0, 0, 20) + }, + entry, + label + } + }; + } +} diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/MauiDoneAccessoryButton.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/MauiDoneAccessoryButton.cs new file mode 100644 index 000000000000..d708aeb5c434 --- /dev/null +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/MauiDoneAccessoryButton.cs @@ -0,0 +1,42 @@ +#if IOS // MauiDoneAccessoryView is iOS only +using NUnit.Framework; +using UITest.Appium; +using UITest.Core; + +namespace Microsoft.Maui.TestCases.Tests.Issues; + +public class MauiDoneAccessoryButton : _IssuesUITest +{ + const string DoneButtonAutomationId = "Microsoft.Maui.Platform.MauiDoneAccessory.DoneButton"; + + public MauiDoneAccessoryButton(TestDevice device) : base(device) + { + } + + public override string Issue => "MauiDoneAccessoryView DoneButton should be accessible for UI testing"; + + [Test] + [Category(UITestCategories.Entry)] + public void DoneButtonShouldHaveAccessibilityIdentifier() + { + // Wait for the entry to be ready + App.WaitForElement("NumericEntry"); + + // Tap the entry to bring up the keyboard + App.Tap("NumericEntry"); + + // Wait for the Done button to appear in the keyboard accessory view + var doneButton = App.WaitForElement(DoneButtonAutomationId); + + // Verify the Done button exists and is accessible + Assert.That(doneButton, Is.Not.Null, "Done button should be accessible via its automation ID"); + + // Tap the Done button + App.Tap(DoneButtonAutomationId); + + // Verify the completed event was triggered + var result = App.FindElement("ResultLabel").GetText(); + Assert.That(result, Does.Contain("completed"), "Done button tap should trigger entry completion"); + } +} +#endif diff --git a/src/Core/src/Platform/iOS/MauiDoneAccessoryView.cs b/src/Core/src/Platform/iOS/MauiDoneAccessoryView.cs index c97349987bfc..009904af393a 100644 --- a/src/Core/src/Platform/iOS/MauiDoneAccessoryView.cs +++ b/src/Core/src/Platform/iOS/MauiDoneAccessoryView.cs @@ -7,6 +7,7 @@ namespace Microsoft.Maui.Platform { internal class MauiDoneAccessoryView : UIToolbar { + const string DoneButtonAutomationId = "Microsoft.Maui.Platform.MauiDoneAccessory.DoneButton"; readonly BarButtonItemProxy _proxy; public MauiDoneAccessoryView() : base(new CGRect(0, 0, UIScreen.MainScreen.Bounds.Width, 44)) @@ -16,6 +17,7 @@ public MauiDoneAccessoryView() : base(new CGRect(0, 0, UIScreen.MainScreen.Bound Translucent = true; var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, _proxy.OnDataClicked); + doneButton.AccessibilityIdentifier = DoneButtonAutomationId; SetItems(new[] { spacer, doneButton }, false); } @@ -33,6 +35,7 @@ public MauiDoneAccessoryView(Action doneClicked) : base(new CGRect(0, 0, UIScree var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, _proxy.OnClicked); + doneButton.AccessibilityIdentifier = DoneButtonAutomationId; SetItems(new[] { spacer, doneButton }, false); }