diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla38731.cs b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla38731.cs index c0dcbcb37ba3..b71d73af2002 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla38731.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla38731.cs @@ -2,30 +2,37 @@ namespace Maui.Controls.Sample.Issues; [Issue(IssueTracker.Bugzilla, 38731, "iOS.NavigationRenderer.GetAppearedOrDisappearedTask NullReferenceExceptionObject", PlatformAffected.iOS)] -public class Bugzilla38731 : TestContentPage +public class Bugzilla38731 : TestNavigationPage { protected override void Init() { - var label = new Label(); - label.Text = "Page one..."; - label.HorizontalTextAlignment = TextAlignment.Center; + Navigation.PushAsync(new PageOne()); + } - var button = new Button(); - button.AutomationId = "btn1"; - button.Text = "Navigate to page two"; - button.Clicked += Button_Clicked; + public class PageOne : ContentPage + { + public PageOne() + { + var label = new Label(); + label.Text = "Page one..."; + label.HorizontalTextAlignment = TextAlignment.Center; - var content = new StackLayout(); - content.Children.Add(label); - content.Children.Add(button); + var button = new Button(); + button.AutomationId = "btn1"; + button.Text = "Navigate to page two"; + button.Clicked += Button_Clicked; - Title = "Page one"; - Content = content; - } + var content = new StackLayout(); + content.Children.Add(label); + content.Children.Add(button); - void Button_Clicked(object sender, EventArgs e) - { - Navigation.PushAsync(new PageTwo()); + Title = "Page one"; + Content = content; + } + void Button_Clicked(object sender, EventArgs e) + { + Navigation.PushAsync(new PageTwo()); + } } public class PageTwo : ContentPage @@ -88,6 +95,7 @@ public PageFour() { var label = new Label(); label.Text = "Last page... Tap back very quick"; + label.AutomationId = "FinalPage"; label.HorizontalTextAlignment = TextAlignment.Center; var content = new StackLayout(); diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40005.cs b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40005.cs index bc8de454bb4c..d1be943d7dfb 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40005.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40005.cs @@ -6,127 +6,122 @@ namespace Maui.Controls.Sample.Issues [Issue(IssueTracker.Bugzilla, 40005, "Navigation Bar back button does not show when using InsertPageBefore")] public class Bugzilla40005 : NavigationPage { - public Bugzilla40005() : base(new MainPage()) + public const string GoToPage2 = "Go to Page 2"; + public const string PageOneLabel = "Page 1"; + public const string PageTwoLabel = "Page 2"; + public const string InsertedPageLabel = "Inserted page"; + public const string TestInstructions = "Click " + GoToPage2 + " and you should still see a back bar button"; + + public Bugzilla40005() : base(new Page1()) { + } + - public class MainPage : ContentPage + public class Page1 : ContentPage { - public const string GoToPage2 = "Go to Page 2"; - public const string PageOneLabel = "Page 1"; - public const string PageTwoLabel = "Page 2"; - public const string InsertedPageLabel = "Inserted page"; - public const string TestInstructions = "Click " + GoToPage2 + " and you should still see a back bar button"; + + bool pageInserted; - public MainPage() + public Page1() { - Application.Current.MainPage = new NavigationPage(new Page1()); - } - - public class Page1 : ContentPage - { - bool pageInserted; - - public Page1() + var btn = new Button() { - var btn = new Button() - { - AutomationId = GoToPage2, - Text = GoToPage2 - }; - btn.Clicked += async (sender, e) => - { - await Navigation.PushAsync(new Page2()); - }; + AutomationId = GoToPage2, + Text = GoToPage2 + }; + btn.Clicked += async (sender, e) => + { + await Navigation.PushAsync(new Page2()); + }; - Content = new StackLayout + Content = new StackLayout + { + VerticalOptions = LayoutOptions.Center, + Children = + { + new Label { - VerticalOptions = LayoutOptions.Center, - Children = + AutomationId = PageOneLabel, + HorizontalTextAlignment = TextAlignment.Center, + Text = PageOneLabel + }, + btn, + new Label { - new Label - { - AutomationId = PageOneLabel, - HorizontalTextAlignment = TextAlignment.Center, - Text = PageOneLabel - }, - btn, - new Label - { - AutomationId = TestInstructions, - HorizontalTextAlignment = TextAlignment.Center, - Text = TestInstructions - } + AutomationId = TestInstructions, + HorizontalTextAlignment = TextAlignment.Center, + Text = TestInstructions } - }; } + }; + } - protected override void OnAppearing() + protected override void OnAppearing() + { + base.OnAppearing(); + if (!pageInserted) { - base.OnAppearing(); - if (!pageInserted) - { - Navigation.InsertPageBefore(new InsertedPage(), this); - pageInserted = true; - } + Navigation.InsertPageBefore(new InsertedPage(), this); + pageInserted = true; } + } - protected override bool OnBackButtonPressed() - { - Debug.WriteLine($"Hardware BackButton Pressed on {PageOneLabel}"); - return base.OnBackButtonPressed(); - } + protected override bool OnBackButtonPressed() + { + Debug.WriteLine($"Hardware BackButton Pressed on {PageOneLabel}"); + return base.OnBackButtonPressed(); } + } - public class InsertedPage : ContentPage + public class InsertedPage : ContentPage + { + public InsertedPage() { - public InsertedPage() + Content = new StackLayout { - Content = new StackLayout - { - VerticalOptions = LayoutOptions.Center, - Children = + VerticalOptions = LayoutOptions.Center, + Children = + { + new Label { - new Label - { - HorizontalTextAlignment = TextAlignment.Center, - Text = InsertedPageLabel - } + HorizontalTextAlignment = TextAlignment.Center, + Text = InsertedPageLabel } - }; } + }; + } - protected override bool OnBackButtonPressed() - { - Debug.WriteLine($"Hardware BackButton Pressed on {InsertedPageLabel}"); - return base.OnBackButtonPressed(); - } + protected override bool OnBackButtonPressed() + { + Debug.WriteLine($"Hardware BackButton Pressed on {InsertedPageLabel}"); + return base.OnBackButtonPressed(); } + } - public class Page2 : ContentPage + public class Page2 : ContentPage + { + public Page2() { - public Page2() + Content = new StackLayout { - Content = new StackLayout - { - VerticalOptions = LayoutOptions.Center, - Children = + VerticalOptions = LayoutOptions.Center, + Children = + { + new Label { - new Label - { - AutomationId = PageTwoLabel, - HorizontalTextAlignment = TextAlignment.Center, - Text = PageTwoLabel - } + AutomationId = PageTwoLabel, + HorizontalTextAlignment = TextAlignment.Center, + Text = PageTwoLabel } - }; } + }; + } - protected override bool OnBackButtonPressed() - { - Debug.WriteLine($"Hardware BackButton Pressed on {PageTwoLabel}"); - return base.OnBackButtonPressed(); - } + protected override bool OnBackButtonPressed() + { + Debug.WriteLine($"Hardware BackButton Pressed on {PageTwoLabel}"); + return base.OnBackButtonPressed(); } } } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40173.cs b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40173.cs index 841c21a8e761..cd358b9ca174 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40173.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla40173.cs @@ -18,7 +18,7 @@ public class Bugzilla40173 : TestContentPage protected override void Init() { - var outputLabel = new Label() { AutomationId = "outputlabel" }; + var outputLabel = new Label() { Text="Default", AutomationId = "outputlabel" }; var testButton = new Button { Text = "Can't Touch This", @@ -78,22 +78,34 @@ protected override void Init() testListView.ItemsSource = items; testListView.ItemTemplate = new DataTemplate(() => { + + var grid = new Grid + { + HeightRequest = 60 + }; + + var itemLabel = new Label + { + VerticalOptions = LayoutOptions.Center, + HorizontalOptions = LayoutOptions.Start + }; + itemLabel.SetBinding(Label.TextProperty, "."); + var boxView = new BoxView + { + Color = Colors.Pink.MultiplyAlpha(0.5f) + }; + boxView.SetBinding(BoxView.AutomationIdProperty, "."); + + grid.Children.Add(itemLabel); + grid.Children.Add(boxView); + var result = new ViewCell { - View = new Grid - { - Children = - { - new BoxView - { - AutomationId = ListTapTarget, - Color = Colors.Pink.MultiplyAlpha(0.5f) - } - } - } + View = grid }; return result; + }); testListView.ItemSelected += (sender, args) => outputLabel.Text = ListTapSuccessText; diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla43527.cs b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla43527.cs index 061392008d9e..6927dd6cf63f 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla43527.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla43527.cs @@ -28,8 +28,7 @@ public TestPage() new Label { Text = "Hello Page" }, new Button { Text = "Change Title", AutomationId = "Change Title", Command = new Command(() => { - Title = $"New Title: {DateTime.Now.Second}"; - AutomationId = Title; + Title = "New Title"; }) } } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla52419.cs b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla52419.cs index f5312e20d51d..659ed3926344 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla52419.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla52419.cs @@ -44,6 +44,7 @@ public Bugzilla52419Page1() new Button { Text = "Push new page", + AutomationId = "PushNewPage", Command = new Command(() => Navigation.PushAsync(new Bugzilla52419Page1())) } } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue10222.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue10222.cs index c448eadde859..1a8f2537acc4 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue10222.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue10222.cs @@ -41,6 +41,7 @@ public CarouselViewTestPage() Margin = new Thickness(0, 100) }; label.SetBinding(Label.TextProperty, new Binding(".")); + label.SetBinding(Label.AutomationIdProperty, new Binding(".")); return label; }) }; diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla32040.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla32040.cs index 44579281aae9..86d2ddd7d17f 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla32040.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla32040.cs @@ -1,4 +1,4 @@ -/* + using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -15,16 +15,16 @@ public Bugzilla32040(TestDevice testDevice) : base(testDevice) [Test] [Category(UITestCategories.Cells)] - [FailsOnIOSWhenRunningOnXamarinUITest] - [FailsOnWindowsWhenRunningOnXamarinUITest] public void TappedWorksForEntryAndSwithCellTest() - { + { App.WaitForElement("blahblah"); - App.Tap("blahblah"); - App.Tap("yaddayadda"); + App.Tap("blahblah"); + App.WaitForElement("Tapped"); + + App.Tap("Click Here"); - Assert.That(App.FindElements("Tapped").Count, - Is.GreaterThanOrEqualTo(2)); + //FindElements consistently returns a zero count, despite the "Tapped" text being visible in the UI. + //Assert.That(App.FindElements("Tapped").Count, Is.GreaterThanOrEqualTo(2)); + App.WaitForTextToBePresentInElement("yaddayadda", "Tapped"); } } -*/ \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla38731.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla38731.cs index 45717daa6e88..38fe6dc2ce1e 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla38731.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla38731.cs @@ -1,5 +1,4 @@ -#if IOS -using NUnit.Framework; +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -7,30 +6,45 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; public class Bugzilla38731 : _IssuesUITest { + +#if ANDROID + const string PageThree = ""; + const string PageTwo = ""; + const string PageOne = ""; +#else + const string PageThree = "Page three"; + const string PageTwo = "Page two"; + const string PageOne = "Page one"; +#endif + const string btn1 = "btn1"; + const string btn2 = "btn2"; + const string btn3 = "btn3"; + public Bugzilla38731(TestDevice testDevice) : base(testDevice) { } public override string Issue => "iOS.NavigationRenderer.GetAppearedOrDisappearedTask NullReferenceExceptionObject"; - // [Test] - // [Category(UITestCategories.Navigation)] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // public void Bugzilla38731Test () - // { - // App.WaitForElement("btn1"); - // App.Tap("btn1"); - - // App.WaitForElement("btn2"); - // App.Tap("btn2"); - - // App.WaitForElement("btn3"); - // App.Tap("btn3"); - - // App.Back(); - // App.Back(); - // App.Back(); - // App.Back(); - // } + [Test] + [Category(UITestCategories.Navigation)] + public void Bugzilla38731Test () + { + App.WaitForElement(btn1); + App.Tap(btn1); + + App.WaitForElement(btn2); + App.Tap(btn2); + + App.WaitForElement(btn3); + App.Tap(btn3); + + App.WaitForElementTillPageNavigationSettled("FinalPage"); + App.TapBackArrow(PageThree); + App.WaitForElementTillPageNavigationSettled(btn3); + App.TapBackArrow(PageTwo); + App.WaitForElementTillPageNavigationSettled(btn2); + App.TapBackArrow(PageOne); + App.WaitForElementTillPageNavigationSettled(btn1); + } } -#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla39331.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla39331.cs index 30c3dffcddb2..ea3d8fc48340 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla39331.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla39331.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_IOS && TEST_FAILS_ON_WINDOWS //Issue reproduced and logged: https://github.com/dotnet/maui/issues/26026. +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,21 +13,18 @@ public Bugzilla39331(TestDevice testDevice) : base(testDevice) public override string Issue => "[Android] BoxView Is InputTransparent Even When Set to False"; - // [FailsOnAndroidWhenRunningOnXamarinUITest] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // [Test] - // [Category(UITestCategories.InputTransparent)] - // public void Bugzilla39331Test() - // { - // App.WaitForElement("btnLogin"); - // App.Tap("btnLogin"); + [Test] + [Category(UITestCategories.InputTransparent)] + public void Bugzilla39331Test() + { + App.WaitForElement("btnLogin"); + App.Tap("btnLogin"); - // App.WaitForTextToBePresentInElement("btnLogin", "Blocked?"); + App.WaitForElement("Blocked?"); - // App.Tap("btnLogin"); + App.Tap("btnLogin"); - // Assert.That(App.FindElement("btnLogin").GetText()? - // .Equals("Guess Not", StringComparison.OrdinalIgnoreCase), - // Is.False); - // } + Assert.That(App.FindElement("btnLogin").GetText()?.Equals("Guess Not", StringComparison.OrdinalIgnoreCase), Is.False); + } } +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40005.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40005.cs index 2a032fcb456b..b22b068e77b2 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40005.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40005.cs @@ -15,23 +15,19 @@ public Bugzilla40005(TestDevice testDevice) : base(testDevice) } public override string Issue => "Navigation Bar back button does not show when using InsertPageBefore"; - - // Crashing when navigating - /* + [Test] [Category(UITestCategories.Navigation)] - [Category(UITestCategories.Compatibility)] - [FailsOnAndroidWhenRunningOnXamarinUITest] - [FailsOnIOSWhenRunningOnXamarinUITest] - [FailsOnMacWhenRunningOnXamarinUITest] public void Bugzilla40005Test() { App.WaitForElement(PageOneLabel); App.Tap(GoToPage2); App.WaitForElement(PageTwoLabel); - App.Back(); + App.TapBackArrow(); App.WaitForElement(PageOneLabel); + App.TapBackArrow(); + App.WaitForElement("Inserted page"); } - */ + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40173.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40173.cs index df06014b85f7..3bc49b23194a 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40173.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla40173.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_ANDROID //Issue reproduced on android and logged the issue: https://github.com/dotnet/maui/issues/26026 +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,24 +13,22 @@ public Bugzilla40173(TestDevice testDevice) : base(testDevice) public override string Issue => "Android BoxView/Frame not clickthrough in ListView"; - // [FailsOnAndroidWhenRunningOnXamarinUITest] - // [FailsOnIOSWhenRunningOnXamarinUITest] - // [Test] - // [Category(UITestCategories.InputTransparent)] - // public void ButtonBlocked() - // { - // App.Tap("CantTouchButtonId"); - - // Assert.That(App.FindElement("outputlabel").GetText()? - // .Equals("Failed", StringComparison.OrdinalIgnoreCase), - // Is.False); - - // App.Tap("CanTouchButtonId"); - - // App.WaitForTextToBePresentInElement("outputlabel", "ButtonTapped"); - // #if !__MACOS__ - // App.Tap("ListTapTarget"); - // App.WaitForTextToBePresentInElement("outputlabel", "ItemTapped"); - // #endif - // } -} \ No newline at end of file + [Test] + [Category(UITestCategories.InputTransparent)] + public void ButtonBlocked() + { + App.WaitForElement("CantTouchButtonId"); + App.Tap("CantTouchButtonId"); + + Assert.That(App.WaitForElement("outputlabel")?.GetText(), Is.EqualTo(("Default"))); + + App.Tap("CanTouchButtonId"); + + Assert.That(App.WaitForElement("outputlabel")?.GetText(), Is.EqualTo(("ButtonTapped"))); + + App.WaitForElement("Foo"); + App.Tap("Foo"); + Assert.That(App.WaitForElement("outputlabel")?.GetText(), Is.EqualTo(("ItemTapped"))); + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla43527.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla43527.cs index 97f13f071f60..d2c4668a8a15 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla43527.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla43527.cs @@ -13,17 +13,13 @@ public Bugzilla43527(TestDevice testDevice) : base(testDevice) public override string Issue => "[UWP] Detail title does not update when wrapped in a NavigationPage"; - // [Test] - // [Category(UITestCategories.FlyoutPage)] - // public void TestB43527UpdateTitle() - // { - // // TODO from Xamarin.UITest migration - // // I'm not sure if this actually verifies the functionality here - // // we might need to add a VerifyScreenshot for this - // // And test is failing so disabled for now - // App.WaitForElement("Change Title"); - // App.WaitForElement("Test Page"); - // App.Tap("Change Title"); - // App.WaitForNoElement("Test Page"); - // } + [Test] + [Category(UITestCategories.FlyoutPage)] + public void TestB43527UpdateTitle() + { + App.WaitForElement("Change Title"); + App.WaitForElement("Test Page"); + App.Tap("Change Title"); + App.WaitForElement("New Title"); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla45926.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla45926.cs index ef1033d21f3f..f1bf075e9625 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla45926.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla45926.cs @@ -6,30 +6,44 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; public class Bugzilla45926 : _IssuesUITest { +#if ANDROID + const string BackButtonIdentifier1 = ""; + const string BackButtonIdentifier2 = ""; +#else + const string BackButtonIdentifier1 = "Back"; + const string BackButtonIdentifier2 = "Test"; +#endif + public Bugzilla45926(TestDevice testDevice) : base(testDevice) { } - public override string Issue => "Effect not attaching to ScrollView"; - - // TODO Xamarin.UITest Migration - // [Test] - // [FailsOnAndroidWhenRunningOnXamarinUITest] - // public void Issue45926Test() - // { - // App.WaitForElement(q => q.Marked("New Page")); - - // App.Tap(q => q.Marked("New Page")); - // App.WaitForElement(q => q.Marked("Second Page #1")); - // App.Back(); - // App.WaitForElement(q => q.Marked("Intermediate Page")); - // App.Back(); - // App.Tap(q => q.Marked("Do GC")); - // App.Tap(q => q.Marked("Do GC")); - // App.Tap(q => q.Marked("Send Message")); - // App.Tap(q => q.Marked("Do GC")); - - // App.WaitForElement(q => q.Marked("Instances: 0")); - // App.WaitForElement(q => q.Marked("Messages: 0")); - // } + public override string Issue => "MessagingCenter prevents subscriber from being collected"; + + [Test] + [Category(UITestCategories.Page)] + public void Issue45926Test() + { + App.WaitForElement("New Page"); + + App.Tap("New Page"); + App.WaitForElementTillPageNavigationSettled("Second Page #1"); + + //Getting nullreference exception on iOS while tapping back button. so using waitforElement for back button element. +#if IOS + App.WaitForElement("Back"); +#endif + + App.TapBackArrow(BackButtonIdentifier1); + App.WaitForElementTillPageNavigationSettled("Intermediate Page"); + App.TapBackArrow(BackButtonIdentifier2); + App.WaitForElement("Do GC"); + App.Tap("Do GC"); + App.Tap("Do GC"); + App.Tap("Send Message"); + App.Tap("Do GC"); + + App.WaitForElement("Instances: 0"); + App.WaitForElement("Messages: 0"); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla52419.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla52419.cs index 25cf3d903ba8..e1fc8e0c32ba 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla52419.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Bugzilla/Bugzilla52419.cs @@ -1,5 +1,4 @@ -#if ANDROID -using NUnit.Framework; +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -7,31 +6,42 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; public class Bugzilla52419 : _IssuesUITest { +#if ANDROID + const string TabPage1 = "TAB PAGE 1"; + const string TabPage2 = "TAB PAGE 2"; + const string BackButtonIdentifier = ""; +#else + const string TabPage1 = "Tab Page 1"; + const string TabPage2 = "Tab Page 2"; + const string BackButtonIdentifier = "Tab Page 1"; +#endif + const string PushNewPage = "PushNewPage"; + const string AppearanceLabel = "AppearanceLabel"; + public Bugzilla52419(TestDevice testDevice) : base(testDevice) { } public override string Issue => "[A] OnAppearing called for previous pages in a tab's navigation when switching active tabs"; - // [Test] - // [Category(UITestCategories.TabbedPage)] - // [FailsOnAndroidWhenRunningOnXamarinUITest] - // public void Bugzilla52419Test() - // { - // App.WaitForElement(q => q.Marked("Push new page")); - // App.Tap(q => q.Marked("Push new page")); - // App.WaitForElement(q => q.Marked("Push new page")); - // App.Tap(q => q.Marked("Push new page")); - // App.WaitForElement(q => q.Marked("Push new page")); - // App.Tap(q => q.Marked("Push new page")); - // App.Tap(q => q.Marked("Tab Page 2")); - // App.Tap(q => q.Marked("Tab Page 1")); - // App.Tap(q => q.Marked("Tab Page 2")); - // App.Tap(q => q.Marked("Tab Page 1")); - // App.Back(); - // App.WaitForElement(q => q.Marked("AppearanceLabel")); - // var label = App.Query(q => q.Marked("AppearanceLabel"))[0]; - // Assert.AreEqual("Times Appeared: 2", label.Text); - // } + [Test] + [Category(UITestCategories.TabbedPage)] + public void Bugzilla52419Test() + { + App.WaitForElementTillPageNavigationSettled(PushNewPage); + App.Tap(PushNewPage); + App.WaitForElementTillPageNavigationSettled(PushNewPage); + App.Tap(PushNewPage); + App.WaitForElementTillPageNavigationSettled(PushNewPage); + App.Tap(PushNewPage); + App.WaitForElementTillPageNavigationSettled(TabPage2); + App.Tap(TabPage2); + App.Tap(TabPage1); + App.Tap(TabPage2); + App.Tap(TabPage1); + App.WaitForElement(PushNewPage); + App.TapBackArrow(BackButtonIdentifier); + App.WaitForElement(AppearanceLabel); + Assert.That(App.WaitForElement(AppearanceLabel).GetText(), Is.EqualTo("Times Appeared: 2")); + } } -#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10222.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10222.cs index 9724773738f0..dee30ab706e2 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10222.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue10222.cs @@ -10,20 +10,17 @@ public Issue10222(TestDevice testDevice) : base(testDevice) { } - public override string Issue => "[Bug] Exception Ancestor must be provided for all pushes except first"; - - // Crash after navigation - /* + public override string Issue => "[CollectionView] ObjectDisposedException if the page is closed during scrolling"; + [Test] [Category(UITestCategories.LifeCycle)] - [Category(UITestCategories.Compatibility)] public void Issue10222Test() { App.WaitForElement("goTo"); App.Tap("goTo"); - App.WaitForElement("collectionView"); + App.WaitForElement("items1"); App.WaitForElement("goTo"); } - */ + } } \ 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 35c93748fffe..a7d398461de5 100644 --- a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs +++ b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs @@ -1779,41 +1779,247 @@ public static IDictionary GetSystemBars(this IApp app) } /// - /// Navigates back in the application by simulating a tap on the platform-specific back navigation button. + /// Navigates back in the application by simulating a tap on the platform-specific back navigation button or using a custom identifier. /// /// The IApp instance representing the main gateway to interact with the application. - /// Optional. The custom identifier for the back button. If not provided, default platform-specific identifiers will be used. + /// Optional custom identifier string for the back button. If not provided, the default back arrow query will be used. public static void TapBackArrow(this IApp app, string customBackButtonIdentifier = "") { - switch (app) + var query = string.IsNullOrEmpty(customBackButtonIdentifier) + ? GetDefaultBackArrowQuery(app) + : GetCustomBackArrowQuery(app, customBackButtonIdentifier); + + TapBackArrow(app, query); + } + + /// + /// Navigates back in the application using a custom IQuery. + /// + /// The IApp instance representing the main gateway to interact with the application. + /// The custom IQuery for the back button. + public static void TapBackArrow(this IApp app, IQuery query) + { + app.Tap(query); + } + + /// + /// Gets the default query for the back arrow button based on the app type. + /// + /// The IApp instance representing the application. + /// An IQuery for the default back arrow button. + /// Thrown when an unsupported app type is provided. + static IQuery GetDefaultBackArrowQuery(IApp app) + { + return app switch + { + AppiumAndroidApp _ => AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc='Navigate up']"), + AppiumIOSApp _ => AppiumQuery.ByAccessibilityId("Back"), + AppiumCatalystApp _ => AppiumQuery.ByAccessibilityId("Back"), + AppiumWindowsApp _ => AppiumQuery.ByAccessibilityId("NavigationViewBackButton"), + _ => throw new ArgumentException("Unsupported app type", nameof(app)) + }; + } + + /// + /// Gets a custom query for the back arrow button based on the app type and a custom identifier. + /// Note that for Windows apps, the back button is not customizable, so the default identifier is used. + /// + /// The IApp instance representing the application. + /// The custom identifier for the back button. + /// An IQuery for the custom back arrow button. + /// Thrown when an unsupported app type is provided. + static IQuery GetCustomBackArrowQuery(IApp app, string customBackButtonIdentifier) + { + return app switch { - case AppiumAndroidApp _: - app.Tap(AppiumQuery.ByXPath(string.IsNullOrEmpty(customBackButtonIdentifier) - ? "//android.widget.ImageButton[@content-desc='Navigate up']" - : $"//android.widget.ImageButton[@content-desc='{customBackButtonIdentifier}']")); - break; + AppiumAndroidApp _ => AppiumQuery.ByXPath($"//android.widget.ImageButton[@content-desc='{customBackButtonIdentifier}']"), + AppiumIOSApp _ => AppiumQuery.ByXPath($"//XCUIElementTypeButton[@name='{customBackButtonIdentifier}']"), + AppiumCatalystApp _ => AppiumQuery.ByName(customBackButtonIdentifier), + AppiumWindowsApp _ => AppiumQuery.ByAccessibilityId("NavigationViewBackButton"), + _ => throw new ArgumentException("Unsupported app type", nameof(app)) + }; + } - case AppiumIOSApp _: - case AppiumCatalystApp _: - if (string.IsNullOrEmpty(customBackButtonIdentifier)) + /// + /// Waits for an element to be ready until page navigation has settled, with additional waiting for MacCatalyst. + /// This method helps prevent null reference exceptions during page transitions, especially in MacCatalyst. + /// + /// The IApp instance. + /// The id of the element to wait for. + /// Optional timeout for the wait operation. Default is null, which uses the default timeout. + public static void WaitForElementTillPageNavigationSettled(this IApp app, string elementId, TimeSpan? timeout = null) + { + if(app is AppiumCatalystApp) + app.WaitForElement(AppiumQuery.ById(elementId), timeout: timeout); + + app.WaitForElement(elementId, timeout: timeout); + } + + /// + /// Waits for an element to be ready until page navigation has settled, with additional waiting for MacCatalyst. + /// This method helps prevent null reference exceptions during page transitions, especially in MacCatalyst. + /// + /// The IApp instance. + /// The query to use for finding the element. + /// Optional timeout for the wait operation. Default is null, which uses the default timeout. + public static void WaitForElementTillPageNavigationSettled(this IApp app, IQuery query, TimeSpan? timeout = null) + { + if(app is AppiumCatalystApp) + app.WaitForElement(query, timeout: timeout); + + app.WaitForElement(query, timeout: timeout); + } + /// + /// Waits for the flyout icon to appear in the app. + /// + /// The IApp instance representing the application. + /// The automation ID of the flyout icon (default is an empty string). + /// Indicates whether the app is using Shell navigation (default is true). + public static void WaitForFlyoutIcon(this IApp app, string automationId = "", bool isShell = true) + { + if(app is AppiumAndroidApp) + { + app.WaitForElement(AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc=\"Open navigation drawer\"]")); + } + else if (app is AppiumIOSApp || app is AppiumCatalystApp || app is AppiumWindowsApp) + { + if(isShell){ + app.WaitForElement("OK"); + } + if (!isShell){ + if(app is AppiumWindowsApp) { - app.Tap(AppiumQuery.ByAccessibilityId("Back")); + app.WaitForElement(AppiumQuery.ByAccessibilityId("TogglePaneButton")); } else { - app.Tap(app is AppiumIOSApp - ? AppiumQuery.ByXPath($"//XCUIElementTypeButton[@name='{customBackButtonIdentifier}']") - : AppiumQuery.ByName(customBackButtonIdentifier)); + app.WaitForElement(automationId); } - break; + } + } + } - case AppiumWindowsApp _: - app.Tap(AppiumQuery.ByAccessibilityId("NavigationViewBackButton")); - break; + /// + /// Shows the flyout menu in the app. + /// + /// The IApp instance representing the application. + /// The automation ID of the flyout icon (default is an empty string). + /// Indicates whether to use swipe gesture to open the flyout (default is false). + /// Indicates whether to wait for the flyout icon before showing the flyout (default is true). + /// Indicates whether the app is using Shell navigation (default is true). + public static void ShowFlyout(this IApp app, string automationId = "", bool usingSwipe = false, bool waitForFlyoutIcon = true, bool isShell = true) + { + if (waitForFlyoutIcon) + { + app.WaitForFlyoutIcon(automationId, isShell); + } + + if (usingSwipe) + { + app.DragCoordinates(5, 500, 800, 500); + } + else + { + app.TapFlyoutIcon(automationId, isShell, false); } } /// + /// Taps the Flyout icon for Shell or FlyoutPage. + /// + /// Represents the main gateway to interact with an app. + /// Optional title for FlyoutPage (default is empty string). + /// Indicates whether the Flyout is for Shell (true) or FlyoutPage (false). + private static void TapFlyoutIcon(this IApp app, string title = "", bool isShell = true, bool waitForFlyoutIcon = true) + { + if (waitForFlyoutIcon) + { + app.WaitForFlyoutIcon(title, isShell); + } + if (app is AppiumAndroidApp) + { + app.Tap(AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc=\"Open navigation drawer\"]")); + } + else if (app is AppiumIOSApp || app is AppiumCatalystApp || app is AppiumWindowsApp) + { + if (isShell) + { + app.Tap(AppiumQuery.ByAccessibilityId("OK")); + } + else + { + if(app is AppiumWindowsApp) + { + app.Tap(AppiumQuery.ByAccessibilityId("TogglePaneButton")); + } + else + { + app.Tap(title); + } + } + } + } + + /// + /// Taps the Flyout icon for Shell pages. + /// + /// Represents the main gateway to interact with an app. + public static void TapShellFlyoutIcon(this IApp app) + { + app.TapFlyoutIcon(); + } + + /// + /// Taps the Flyout icon for FlyoutPage. + /// + /// Represents the main gateway to interact with an app. + /// Optional title for FlyoutPage (default is empty string). + public static void TapFlyoutPageIcon(this IApp app, string title = "") + { + app.TapFlyoutIcon(title, false); + } + + /// + /// Taps an item in the specified flyout menu. + /// + /// The IApp instance representing the application. + /// The text or accessibility identifier of the flyout item to tap. + /// True if it's a Shell flyout, false for FlyoutPage flyout. + private static void TapInFlyout(this IApp app, string flyoutItem, bool isShellFlyout) + { + if (isShellFlyout) + { + app.TapShellFlyoutIcon(); + } + else + { + app.TapFlyoutPageIcon(); + } + + app.WaitForElement(flyoutItem); + app.Tap(flyoutItem); + } + + /// + /// Taps an item in the Shell flyout menu. + /// + /// The IApp instance representing the application. + /// The text or accessibility identifier of the flyout item to tap. + public static void TapInShellFlyout(this IApp app, string flyoutItem) + { + app.TapInFlyout(flyoutItem, true); + } + + /// + /// Taps an item in the FlyoutPage flyout menu. + /// + /// The IApp instance representing the application. + /// The text or accessibility identifier of the flyout item to tap. + public static void TapInFlyoutPageFlyout(this IApp app, string flyoutItem) + { + app.TapInFlyout(flyoutItem, false); + } + /// Taps the "More" button in the app, with platform-specific logic for Android and Windows. /// This method does not currently support iOS and macOS platforms, where the "More" button is not shown. ///