diff --git a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue1658.cs b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue1658.cs index e0ee29bfaa89..bb28984a4263 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue1658.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue1658.cs @@ -24,20 +24,18 @@ protected override void Init() AutomationId = "coffee.png" }); - var box = new BoxView + var label = new Label { - WidthRequest = 30, - HeightRequest = 30, - Color = Colors.Red, - AutomationId = "ColorBox" + Text = "Tap label", + AutomationId = "labelId" }; var gr = new TapGestureRecognizer(); gr.Command = new Command(() => { - box.Color = box.Color == Colors.Red ? Colors.Yellow : Colors.Red; + label.Text = label.Text == "Tap label" ? "Success" : "Tap label"; }); - box.GestureRecognizers.Add(gr); + label.GestureRecognizers.Add(gr); cells.View = new StackLayout() { Orientation = StackOrientation.Horizontal, @@ -46,9 +44,11 @@ protected override void Init() new Label() { Text = "Right click on any item within viewcell (including this label) should trigger context action on this row and you should see a coffee cup. Tap on colored box should change box color", - AutomationId = "ListViewItem" + AutomationId = "ListViewItem", + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.FillAndExpand }, - box + label } }; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue4314.cs b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue4314.cs index 708577eb4eb1..439833729bc8 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue4314.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue4314.cs @@ -1,25 +1,147 @@ -//using Microsoft.Maui.Controls.CustomAttributes; -//using Microsoft.Maui.Controls.Internals; - -//namespace Maui.Controls.Sample.Issues; - -//[Issue(IssueTracker.Github, 4314, "When ListView items is removed and it is empty, Xamarin Forms crash", PlatformAffected.iOS)] -//public class Issue4314 : TestNavigationPage -//{ -// const string Success = "Success"; - -// MessagesViewModel viewModel; -// protected override void Init() -// { -// var page = new ContextActionsGallery(false, true, 2) { Title = "Swipe and delete both" }; -// viewModel = page.BindingContext as MessagesViewModel; -// viewModel.Messages.CollectionChanged += (s, e) => -// { -// if (viewModel.Messages.Count == 0) -// { -// Navigation.PushAsync(new ContentPage { Title = "Success", Content = new Label { Text = Success } }); -// } -// }; -// Navigation.PushAsync(page); -// } -//} \ No newline at end of file +using Microsoft.Maui.Controls.CustomAttributes; +using Microsoft.Maui.Controls.Internals; +using System.Collections.ObjectModel; +using System.Windows.Input; + +namespace Maui.Controls.Sample.Issues; + +[Issue(IssueTracker.Github, 4314, "When ListView items is removed and it is empty, Xamarin Forms crash", PlatformAffected.iOS)] +public class Issue4314 : TestNavigationPage +{ + const string Success = "Success"; + + MessagesViewModel viewModel; + protected override void Init() + { + var page = new ContextActionsGallery(false, true, 2) { Title = "Swipe and delete both" }; + viewModel = page.BindingContext as MessagesViewModel; + viewModel.Messages.CollectionChanged += (s, e) => + { + if (viewModel.Messages.Count == 0) + { + Navigation.PushAsync(new ContentPage { Title = "Success", Content = new Label { Text = Success } }); + } + }; + Navigation.PushAsync(page); + } +} + +internal class MessagesViewModel : ViewModelBase +{ + public MessagesViewModel(int messagesCount) + { + Messages = new ObservableCollection(Enumerable.Range(0, messagesCount).Select(i => + { + return new MessageViewModel { Subject = "Subject Line " + i, MessagePreview = "Lorem ipsum dolorem monkeys bonkers " + i }; + })); + + MessagingCenter.Subscribe(this, "DeleteMessage", (vm, vm2) => + { + Messages.Remove(vm); + }); + } + + public ObservableCollection Messages + { + get; + private set; + } +} + +[Preserve(AllMembers = true)] +public class MessageViewModel : ViewModelBase +{ + public MessageViewModel() + { + Delete = new Command(() => MessagingCenter.Send(this, "DeleteMessage", this)); + Move = new Command(() => MessagingCenter.Send(this, "MoveMessage", this)); + } + + public string Subject + { + get; + set; + } + + public string MessagePreview + { + get; + set; + } + + public ICommand Delete + { + get; + private set; + } + + public ICommand Move + { + get; + private set; + } +} + +internal class ContextActionsGallery : ContentPage +{ + class MessageCell : TextCell + { + public MessageCell() + { + this.SetBinding(TextProperty, "Subject"); + this.SetBinding(DetailProperty, "MessagePreview"); + + var delete = new MenuItem { Text = "Delete", IsDestructive = true }; + delete.SetBinding(MenuItem.CommandProperty, "Delete"); + + var mark = new MenuItem { Text = "Mark", IconImageSource = "calculator.png" }; + var move = new MenuItem { Text = "Move" }; + + //move.Clicked += async (sender, e) => await Navigation.PopAsync(); + + ContextActions.Add(mark); + ContextActions.Add(delete); + ContextActions.Add(move); + + var clear = new MenuItem { Text = "Clear Items" }; + clear.Clicked += (sender, args) => ContextActions.Clear(); + ContextActions.Add(clear); + } + } + + public ContextActionsGallery(bool tableView = false, bool hasUnevenRows = false, int messagesCount = 100) + { + BindingContext = new MessagesViewModel(messagesCount); + + View list; + if (!tableView) + { + list = new ListView + { + HasUnevenRows = hasUnevenRows + }; + list.SetBinding(ListView.ItemsSourceProperty, "Messages"); + ((ListView)list).ItemTemplate = new DataTemplate(typeof(MessageCell)); + } + else + { + var section = new TableSection(); + section.Add(new TextCell { Text = "I have no ContextActions", Detail = "Sup" }); + foreach (var msg in ((MessagesViewModel)BindingContext).Messages) + { + section.Add(new MessageCell { BindingContext = msg }); + } + + list = new TableView(); + ((TableView)list).Root = new TableRoot { section }; + } + + Content = new StackLayout + { + Children = { + new Label { Text = "Email" }, + list + } + }; + } +} \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla31330.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla31330.cs index ba65aa5d7e1d..cacefeaad897 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla31330.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla31330.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,23 +14,20 @@ public Bugzilla31330(TestDevice testDevice) : base(testDevice) public override string Issue => "Disabled context actions appear enabled"; - // TODO: porting over from Xamarin.UITest - // We don't seem to have "ActivateContextMenu" (yet)? - // [FailsOnAndroidWhenRunningOnXamarinUITest] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // [Test] - //[Category(UITestCategories.ListView)] - // public void Bugzilla31330Test() - // { - // App.WaitForElement("Something 2"); - // App.ActivateContextMenu("Something 1"); - // App.WaitForElement("Delete"); - // App.Tap("Delete"); - // App.DismissContextMenu(); - // App.Tap("Something 2"); - // App.ActivateContextMenu("Something 2"); - // App.WaitForElement("Delete"); - // App.Tap("Delete"); - // App.WaitForNoElement("Something 2"); - // } -} \ No newline at end of file + [Test] + [Category(UITestCategories.ListView)] + public void Bugzilla31330Test() + { + App.WaitForElement("Something 2"); + App.ActivateContextMenu("Something 1"); + App.WaitForElement("Delete"); + App.Tap("Delete"); + App.DismissContextMenu(); + App.Tap("Something 2"); + App.ActivateContextMenu("Something 2"); + App.WaitForElement("Delete"); + App.Tap("Delete"); + App.WaitForNoElement("Something 2"); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla57317.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla57317.cs index 6a7f74799d07..1f8974e1c63b 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla57317.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla57317.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -6,8 +8,6 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; public class Bugzilla57317 : _IssuesUITest { - const string Success = "Success"; - const string BtnAdd = "btnAdd"; public Bugzilla57317(TestDevice testDevice) : base(testDevice) { @@ -15,16 +15,16 @@ public Bugzilla57317(TestDevice testDevice) : base(testDevice) public override string Issue => "Modifying Cell.ContextActions can crash on Android"; - // [Test] - // [Category(UITestCategories.TableView)] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // public void Bugzilla57317Test() - // { - // App.WaitForFirstElement("Cell"); + [Test] + [Category(UITestCategories.TableView)] + public void Bugzilla57317Test() + { + App.WaitForFirstElement("Cell"); - // App.ActivateContextMenu("Cell"); + App.ActivateContextMenu("Cell"); - // App.WaitForFirstElement("Self-Deleting item"); - // App.Tap(c => c.Marked("Self-Deleting item")); - // } -} \ No newline at end of file + App.WaitForFirstElement("Self-Deleting item"); + App.Tap("Self-Deleting item"); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58833.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58833.cs index aff3727be02c..088393871a42 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58833.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58833.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,35 +14,28 @@ public Bugzilla58833(TestDevice testDevice) : base(testDevice) public override string Issue => "ListView SelectedItem Binding does not fire"; - // [Test] - // [Category(UITestCategories.ListView)] - // [Ignore("Failing without explanation on XTC, please run manually")] - // public void Bugzilla58833Test() - // { - // // Item #1 should not have a tap gesture, so it should be selectable - // App.WaitForElement(q => q.Marked("Item #1")); - // App.Tap(q => q.Marked("Item #1")); - // App.WaitForElement(q => q.Marked(ItemSelectedSuccess)); - - // // Item #2 should have a tap gesture - // App.WaitForElement(q => q.Marked("Item #2")); - // App.Tap(q => q.Marked("Item #2")); - // App.WaitForElement(q => q.Marked(TapGestureSucess)); - - // // Both items should allow access to the context menu - // App.ActivateContextMenu("Item #2"); - // App.WaitForElement("2 Action"); - // #if __ANDROID__ - // App.Back(); - // #else - // App.Tap(q => q.Marked("Item #3")); - - - // App.ActivateContextMenu("Item #1"); - // App.WaitForElement("1 Action"); - // #if __ANDROID__ - // App.Back(); - // #else - // App.Tap(q => q.Marked("Item #3")); - // } -} \ No newline at end of file + [Test] + [Category(UITestCategories.ListView)] + public void Bugzilla58833Test() + { + // Item #1 should not have a tap gesture, so it should be selectable + App.WaitForElement("Item #1"); + App.Tap("Item #1"); + App.WaitForElement("ItemSelected Success"); + + // Item #2 should have a tap gesture + App.WaitForElement("Item #2"); + App.Tap("Item #2"); + App.WaitForElement("TapGesture Fired"); + + // Both items should allow access to the context menu + App.ActivateContextMenu("Item #2"); + App.WaitForElement("2 Action"); + App.DismissContextMenu(); + + App.ActivateContextMenu("Item #1"); + App.WaitForElement("1 Action"); + App.DismissContextMenu(); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58875.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58875.cs index 587dfe84e4ca..d768bc6ebce2 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58875.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla58875.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -6,31 +8,30 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; public class Bugzilla58875 : _IssuesUITest { + const string Button1Id = "Button1Id"; + const string Target = "Swipe me"; public Bugzilla58875(TestDevice testDevice) : base(testDevice) { } public override string Issue => "Back navigation disables Context Action in whole app, if Context Action left open"; - // [Test] - // [Category(UITestCategories.ContextActions)] - // public void Bugzilla58875Test() - // { - // App.WaitForElement(q => q.Marked(Button1Id)); - // App.Tap(q => q.Marked(Button1Id)); - // App.WaitForElement(q => q.Marked(Target)); - // App.ActivateContextMenu(Target); - // App.WaitForElement(q => q.Marked(ContextAction)); - // App.Back(); - - // #if ANDROID - // App.Back(); // back button dismisses the ContextAction first, so we need to hit back one more time to get to previous page - // #endif - - // App.WaitForElement(q => q.Marked(Button1Id)); - // App.Tap(q => q.Marked(Button1Id)); - // App.WaitForElement(q => q.Marked(Target)); - // App.ActivateContextMenu(Target); - // App.WaitForElement(q => q.Marked(ContextAction)); - // } -} \ No newline at end of file + [Test] + [Category(UITestCategories.ContextActions)] + public void Bugzilla58875Test() + { + App.WaitForElement(Button1Id); + App.Tap(Button1Id); + App.WaitForElement(Target); + App.ActivateContextMenu(Target); + App.WaitForElement("More"); + App.DismissContextMenu(); + App.TapBackArrow(); + App.WaitForElement(Button1Id); + App.Tap(Button1Id); + App.WaitForElement(Target); + App.ActivateContextMenu(Target); + App.WaitForElement("More"); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla59580.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla59580.cs index aa7905ba86d7..c7edf4eeb97a 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla59580.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla59580.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,17 +14,17 @@ public Bugzilla59580(TestDevice testDevice) : base(testDevice) public override string Issue => "Raising Command.CanExecutChanged causes crash on Android"; - // [Test] - // [Category(UITestCategories.TableView)] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // public void RaisingCommandCanExecuteChangedCausesCrashOnAndroid() - // { - // App.WaitForElement(c => c.Marked("Cell")); + [Test] + [Category(UITestCategories.TableView)] + public void RaisingCommandCanExecuteChangedCausesCrashOnAndroid() + { + App.WaitForElement("Cell"); - // App.ActivateContextMenu("Cell"); + App.ActivateContextMenu("Cell"); - // App.WaitForElement(c => c.Marked("Fire CanExecuteChanged")); - // App.Tap(c => c.Marked("Fire CanExecuteChanged")); - // App.WaitForElement("Cell"); - // } -} \ No newline at end of file + App.WaitForElement("Fire CanExecuteChanged"); + App.Tap("Fire CanExecuteChanged"); + App.WaitForElement("Cell"); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3653.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3653.cs index b7e8eb5a6942..97f089b29823 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3653.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue3653.cs @@ -1,50 +1,49 @@ -#if !WINDOWS +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 using NUnit.Framework; using UITest.Appium; using UITest.Core; namespace Microsoft.Maui.TestCases.Tests.Issues; -public class Issue3653 : _IssuesUITest +public class Issue3652 : _IssuesUITest { - public Issue3653(TestDevice testDevice) : base(testDevice) + public Issue3652(TestDevice testDevice) : base(testDevice) { } public override string Issue => "Loses the correct reference to the cell after adding and removing items to a ListView"; - // [Test] - // [Category(UITestCategories.ContextActions)] - // [FailsOnAndroid] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // public void TestRemovingContextMenuItems() - // { - // for (int i = 1; i <= 3; i++) - // { - // string searchFor = $"Remove me using the context menu. #{i}"; - // App.WaitForElement(searchFor); - - // App.ActivateContextMenu(searchFor); - // App.WaitForElement(c => c.Marked("Remove")); - // App.Tap(c => c.Marked("Remove")); - // } - - // for (int i = 4; i <= 6; i++) - // { - // App.Tap("Add an item"); - // string searchFor = $"Remove me using the context menu. #{i}"; - - // App.ActivateContextMenu(searchFor); - // App.WaitForElement(c => c.Marked("Remove")); - // App.Tap(c => c.Marked("Remove")); - // } - - - // for (int i = 1; i <= 6; i++) - // { - // string searchFor = $"Remove me using the context menu. #{i}"; - // App.WaitForNoElement(c => c.Marked("Remove")); - // } - // } + [Test] + [Category(UITestCategories.ContextActions)] + public void TestRemovingContextMenuItems() + { + for (int i = 1; i <= 3; i++) + { + string searchFor = $"Remove me using the context menu. #{i}"; + App.WaitForElement(searchFor); + + App.ActivateContextMenu(searchFor); + App.WaitForElement("Remove"); + App.Tap("Remove"); + } + + for (int i = 4; i <= 6; i++) + { + App.Tap("Add an item"); + string searchFor = $"Remove me using the context menu. #{i}"; + + App.ActivateContextMenu(searchFor); + App.WaitForElement("Remove"); + App.Tap("Remove"); + } + + + for (int i = 1; i <= 6; i++) + { + string searchFor = $"Remove me using the context menu. #{i}"; + App.WaitForNoElement(searchFor); + } + } } #endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/GitHub1331.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/GitHub1331.cs index 6800e6573489..49675590a98c 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/GitHub1331.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/GitHub1331.cs @@ -1,4 +1,5 @@ -#if ANDROID // This test only makes sense on platforms using Long Press to activate context menus +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -7,28 +8,32 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; public class GitHub1331 : _IssuesUITest { + const string Action = "Action 1"; + const string ActionItemTapped = "Action Item Tapped"; + const string CellItem = "item 1"; + public GitHub1331(TestDevice testDevice) : base(testDevice) { } public override string Issue => "[Android] ViewCell shows ContextActions on tap instead of long press"; - // [Test] - // [Category(UITestCategories.Gestures)] - // public void SingleTapOnCellDoesNotActivateContext() - // { - // App.WaitForElement(Action); + [Test] + [Category(UITestCategories.Gestures)] + public void SingleTapOnCellDoesNotActivateContext() + { + App.WaitForElement(Action); - // App.Tap(Action); - // App.WaitForElement(ActionItemTapped); + App.Tap(Action); + App.WaitForElement(ActionItemTapped); - // // Tapping the part of the cell without a tap gesture should *not* display the context action - // App.Tap(CellItem); - // App.WaitForNoElement("Context Action"); + // Tapping the part of the cell without a tap gesture should *not* display the context action + App.Tap(CellItem); + App.WaitForNoElement("Context Action"); - // // But a Long Press *should* still display the context action - // App.TouchAndHold(CellItem); - // App.WaitForElement("Context Action"); - // } + // But a Long Press *should* still display the context action + App.ActivateContextMenu(CellItem); + App.WaitForElement("Context Action"); + } } -#endif \ No newline at end of file +#endif diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1658.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1658.cs index 58d028e8e2a8..143754b4a996 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1658.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1658.cs @@ -1,4 +1,5 @@ -#if MACCATALYST +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS// The automation ID for the image icon in the Windows context menu is not working in Appium. +//ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,19 +13,18 @@ public Issue1658(TestDevice testDevice) : base(testDevice) } public override string Issue => "[macOS] GestureRecognizer on ListView Item not working"; - - // [Test] - // [Category(UITestCategories.ListView)] - // public void ContextActionsIconImageSource() - // { - // App.ActivateContextMenu("ListViewItem"); - // App.WaitForElement("coffee.png"); - // App.DismissContextMenu(); - // App.WaitForElement("ColorBox"); - // App.Screenshot("Box should be red"); - // App.Tap("ColorBox"); - // App.Screenshot("Box should be yellow"); - // } + [Test] + [Category(UITestCategories.ActivityIndicator)] + public void ContextActionsIconImageSource() + { + App.WaitForElement("ListViewItem"); + App.ActivateContextMenu("ListViewItem"); + App.WaitForElement(AppiumQuery.ByAccessibilityId("coffee.png")); + App.DismissContextMenu(); + Assert.That(App.WaitForElement("labelId").GetText(), Is.EqualTo("Tap label")); + App.Tap("labelId"); + Assert.That(App.WaitForElement("labelId").GetText(), Is.EqualTo("Success")); + } } #endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2414.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2414.cs index 07d72fdd7d71..088edae023a8 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2414.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2414.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,24 +14,15 @@ public Issue2414(TestDevice testDevice) : base(testDevice) public override string Issue => "NullReferenceException when swiping over Context Actions"; - // [Test] - // [Category(UITestCategories.TableView)] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // public void TestDoesntCrashShowingContextMenu() - // { - // App.ActivateContextMenu("Swipe ME"); - // App.WaitForElement(c => c.Marked("Text0")); - // App.Screenshot("Didn't crash"); - // App.Tap(c => c.Marked("Text0")); - // } - - // [Test] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // public void TestShowContextMenuItemsInTheRightOrder() - // { - // App.ActivateContextMenu("Swipe ME"); - // App.WaitForElement(c => c.Marked("Text0")); - // App.Screenshot("Are the menuitems in the right order?"); - // App.Tap(c => c.Marked("Text0")); - // } + [Test] + [Category(UITestCategories.TableView)] + public void TestShowContextMenuItemsInTheRightOrder() + { + App.WaitForElement("Swipe ME"); + App.ActivateContextMenu("Swipe ME"); + App.WaitForElement("Text0"); + App.Tap("Text0"); + App.WaitForElement("Swipe ME"); + } } +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue4314.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue4314.cs index 6e674f99dd97..86f7655bc492 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue4314.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue4314.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST //ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. +//For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,20 +14,20 @@ public Issue4314(TestDevice testDevice) : base(testDevice) public override string Issue => "When ListView items is removed and it is empty, Xamarin Forms crash"; - // TODO: See HostApp UI class for this, some supporting types are missing from code there. We probably need to get those our of the ControlGallery project or replace them - //[Test] - //[Category(UITestCategories.ContextActions)] - //public void Issue4341Test() - //{ - // App.WaitForElement(c => c.Marked("Email")); - // App.ActivateContextMenu("Subject Line 0"); - // App.WaitForElement("Delete"); - // App.Tap("Delete"); - // App.ActivateContextMenu("Subject Line 1"); - // App.Tap("Delete"); - // App.WaitForElement(c => c.Marked(Success)); - // App.Back(); - // App.WaitForElement(c => c.Marked("Email")); - // App.SwipeRightToLeft(); - //} -} \ No newline at end of file + [Test] + [Category(UITestCategories.ContextActions)] + public void Issue4341Test() + { + App.WaitForElement("Email"); + App.ActivateContextMenu("Subject Line 0"); + App.WaitForElement("Delete"); + App.Tap("Delete"); + App.ActivateContextMenu("Subject Line 1"); + App.Tap("Delete"); + App.WaitForElement("Success"); + App.TapBackArrow(); + App.WaitForElement("Email"); + App.SwipeRightToLeft(); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6258.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6258.cs index 5ad689296f6e..c8e36837f264 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6258.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6258.cs @@ -1,4 +1,6 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_IOS && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS// The automation ID for the image icon in the Windows context menu is not working in Appium. +//ContextActions Menu Items Not Accessible via Automation on iOS and Catalyst Platforms. For more information see Issue Link: https://github.com/dotnet/maui/issues/27394 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,12 +14,13 @@ public Issue6258(TestDevice testDevice) : base(testDevice) public override string Issue => "[Android] ContextActions icon not working"; - //[Test] - //[Category(UITestCategories.ListView)] - //public void ContextActionsIconImageSource() - //{ - // App.WaitForElement("ListViewItem"); - // App.ActivateContextMenu("ListViewItem"); - // App.WaitForElement("coffee.png"); - //} -} \ No newline at end of file + [Test] + [Category(UITestCategories.ListView)] + public void ContextActionsIconImageSource() + { + App.WaitForElement("ListViewItem"); + App.ActivateContextMenu("ListViewItem"); + App.WaitForElement(AppiumQuery.ByAccessibilityId("coffee.png")); + } +} +#endif \ No newline at end of file diff --git a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs index aee99d2483dc..7591114a27b6 100644 --- a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs +++ b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs @@ -2288,6 +2288,56 @@ public static IUIElement WaitForTabElement(this IApp app, string tabName) return app.WaitForElementTillPageNavigationSettled(tabName); } + /// + /// Performs platform-specific context actions (e.g., long press, swipe, or touch-and-hold) on a specified element in the app. + /// - On Android, it performs a long press gesture on the element. + /// - On Windows, it simulates a right-click (touch-and-hold) on the element. + /// - On iOS, it performs a swipe from right to left on the element. + /// - On Catalyst, it performs a scroll from right to left on the element. + /// + /// Represents the main gateway to interact with an app. + /// The element on which to perform the context action. + public static void ActivateContextMenu(this IApp app, string element) + { + var uiElement = WaitForElement(app, element); + + switch (app) + { + case AppiumAndroidApp _: + app.LongPress(element); + break; + case AppiumWindowsApp _: + app.TouchAndHold(uiElement); + break; + case AppiumIOSApp _: + app.SwipeRightToLeft(uiElement, swipePercentage: 5, swipeSpeed: 500, withInertia: true); + break; + case AppiumCatalystApp _: + app.ScrollRight(uiElement, swipePercentage: 5, swipeSpeed: 500, withInertia: true); + break; + } + } + + /// + /// Dismisses the context menu in the application. + /// + /// The IApp instance representing the application. + /// + /// For Android apps, it taps the back arrow. + /// For other platforms, it taps at coordinates (150, 150). + /// + public static void DismissContextMenu(this IApp app) + { + if (app is AppiumAndroidApp) + { + app.TapBackArrow(); + } + else + { + app.TapCoordinates(150, 150); + } + } + static IUIElement Wait(Func query, Func satisfactory, string? timeoutMessage = null,