From 224a010e5588d3e98236c57ddd4852cf16d0a841 Mon Sep 17 00:00:00 2001 From: Anandhan Rajagopal <97146406+anandhan-rajagopal@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:49:40 +0530 Subject: [PATCH 1/4] enabled ui tests from xamarinuitests into appium --- .../Issues/XFIssue/GitHub1776.cs | 8 +++--- .../Issues/XFIssue/Issue2953.cs | 1 + .../Issues/XFIssue/Issue8008.cs | 8 +++--- .../Tests/Issues/XFIssue/Github1776.cs | 27 +++++++++---------- .../Tests/Issues/XFIssue/Issue12320.cs | 17 ++++++------ .../Tests/Issues/XFIssue/Issue2953.cs | 20 ++++++-------- .../Tests/Issues/XFIssue/Issue8008.cs | 13 +++++---- 7 files changed, 42 insertions(+), 52 deletions(-) diff --git a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/GitHub1776.cs b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/GitHub1776.cs index 822e22c28767..3854be9c85d8 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/GitHub1776.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/GitHub1776.cs @@ -54,10 +54,10 @@ int CommandCount protected override void Init() { - PressedLabel = new Label(); - ReleasedLabel = new Label(); - ClickedLabel = new Label(); - CommandLabel = new Label(); + PressedLabel = new Label { AutomationId = "PressedLabel" }; + ReleasedLabel = new Label { AutomationId = "ReleasedLabel" }; + ClickedLabel = new Label { AutomationId = "ClickedLabel" }; + CommandLabel = new Label { AutomationId = "CommandLabel" }; var button = new Button { diff --git a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue2953.cs b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue2953.cs index 9e5654df4713..1a60bc6ea07c 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue2953.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue2953.cs @@ -57,6 +57,7 @@ public HeaderCell() Height = 44; var label = new Label { BackgroundColor = Colors.Pink }; label.SetBinding(Label.TextProperty, "GroupName"); + label.SetBinding(Label.AutomationIdProperty, "GroupName"); View = label; } } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue8008.cs b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue8008.cs index 649d63784e02..e536abdfc49f 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue8008.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue8008.cs @@ -32,14 +32,12 @@ protected override void Init() }); item2.Title = "Visible After Remove"; -#pragma warning disable CS0618 // Type or member is obsolete -#pragma warning disable CS0612 // Type or member is obsolete - Device.BeginInvokeOnMainThread(() => + + MainThread.BeginInvokeOnMainThread(() => { this.Items.Remove(item1); }); -#pragma warning restore CS0612 // Type or member is obsolete -#pragma warning restore CS0618 // Type or member is obsolete + } } diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Github1776.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Github1776.cs index 91a0cde0ad05..daf90814e4f8 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Github1776.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Github1776.cs @@ -1,5 +1,4 @@ -#if MACCATALYST -using NUnit.Framework; +using NUnit.Framework; using NUnit.Framework.Legacy; using UITest.Appium; using UITest.Core; @@ -14,17 +13,15 @@ public Github1776(TestDevice testDevice) : base(testDevice) public override string Issue => "Button Released not being triggered"; - // [Test] - // [Category(UITestCategories.Button)] - // public void GitHub1776Test() - // { - // App.WaitForElement(q => q.Marked("TheButton")); - // App.Tap(q => q.Marked("TheButton")); - - // Assert.AreEqual(1, _pressedCount, "Pressed should fire once per tap"); - // Assert.AreEqual(1, _releasedCount, "Released should fire once per tap"); - // Assert.AreEqual(1, _clickedCount, "Clicked should fire once per tap"); - // Assert.AreEqual(1, _commandCount, "Command should fire once per tap"); - // } + [Test] + [Category(UITestCategories.Button)] + public void GitHub1776Test() + { + App.WaitForElement("TheButton"); + App.Tap("TheButton"); + Assert.That(App.FindElement("PressedLabel").GetText(), Is.EqualTo("Pressed: 1")); + Assert.That(App.FindElement("ReleasedLabel").GetText(), Is.EqualTo("Released: 1")); + Assert.That(App.FindElement("ClickedLabel").GetText(), Is.EqualTo("Clicked: 1")); + Assert.That(App.FindElement("CommandLabel").GetText(), Is.EqualTo("Command: 1")); + } } -#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs index b7240590cc7a..4f7fd6d06582 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs @@ -12,13 +12,12 @@ public Issue12320(TestDevice testDevice) : base(testDevice) public override string Issue => "[iOS] TabBarIsVisible = True/False doesn't work on Back Navigation When using BackButtonBehavior"; - // Where does TapBackArrow come from? - // [Test] - // [Category(UITestCategories.Shell)] - // public void PopLogicExecutesWhenUsingBackButtonBehavior() - // { - // App.WaitForElement("TestReady"); - // base.TapBackArrow(); - // App.WaitForElement("Tab 1"); - // } + [Test] + [Category(UITestCategories.Shell)] + public void PopLogicExecutesWhenUsingBackButtonBehavior() + { + App.WaitForElement("TestReady"); + App.TapBackArrow(); + App.WaitForElement("Tab 1"); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2953.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2953.cs index d58aed568090..8031b9ed01c3 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2953.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue2953.cs @@ -12,16 +12,12 @@ public Issue2953(TestDevice testDevice) : base(testDevice) public override string Issue => "GroupHeaderCells disappear when item is removed from a group in ListView (iOS only) "; - // [Test] - // [Category(UITestCategories.ListView)] - // [FailsOnIOS] - // public void Issue2953Test() - // { - // App.Screenshot("I am at Issue 2953"); - // App.WaitForElement(q => q.Marked("Header 3")); - // App.Screenshot("I see the Header 3"); - // App.Tap(q => q.Marked("btnRemove")); - // App.WaitForElement(q => q.Marked("Header 3")); - // App.Screenshot("I still see the Header 3"); - // } + [Test] + [Category(UITestCategories.ListView)] + public void Issue2953Test() + { + App.WaitForElement("Header 3"); + App.Tap("btnRemove"); + App.WaitForElement("Header 3"); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8008.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8008.cs index bbf1cca39426..fcf4374c9174 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8008.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8008.cs @@ -12,11 +12,10 @@ public Issue8008(TestDevice testDevice) : base(testDevice) public override string Issue => "Removing Shell Item can cause Shell to try and set a MenuItem as the default visible item"; - //[Test] - //[Category(UITestCategories.Shell)] - //[FailsOnIOS] - //public void RemovingShellItemCorrectlyPicksNextValidShellItemAsVisibleShellItem() - //{ - // App.WaitForElement("Success"); - //} + [Test] + [Category(UITestCategories.Shell)] + public void RemovingShellItemCorrectlyPicksNextValidShellItemAsVisibleShellItem() + { + App.WaitForElement("Success"); + } } \ No newline at end of file From 585f4eb50fef2f44440ce24d22ba799523268336 Mon Sep 17 00:00:00 2001 From: Anandhan Rajagopal <97146406+anandhan-rajagopal@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:52:46 +0530 Subject: [PATCH 2/4] Updated the TabBackArrow() method --- .../Tests/Issues/XFIssue/Issue12320.cs | 6 ++++-- .../src/UITest.Appium/HelperExtensions.cs | 20 +++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs index 4f7fd6d06582..570ad8f95e6a 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_CATALYST // In Catalyst App.TapBackArrow() not working when override the back button icon of the navigation page. +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -20,4 +21,5 @@ public void PopLogicExecutesWhenUsingBackButtonBehavior() App.TapBackArrow(); App.WaitForElement("Tab 1"); } -} \ No newline at end of file +} +#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 a63dd680ca38..4d89487aaaa1 100644 --- a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs +++ b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs @@ -1679,6 +1679,26 @@ public static IList GetPerformanceData(this IApp app, string performance throw new InvalidOperationException($"Could not get the performance data"); } + /// + /// Navigates back in the application by simulating a tap on the platform-specific back navigation button. + /// + /// Represents the main gateway to interact with an app. + public static void TapBackArrow(this IApp app) + { + if (app is AppiumAndroidApp) + { + app.Tap(AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc='Navigate up']")); + } + else if (app is AppiumIOSApp || app is AppiumCatalystApp) + { + app.Tap(AppiumQuery.ByAccessibilityId("Back")); + } + else if (app is AppiumWindowsApp) + { + app.Tap(AppiumQuery.ByAccessibilityId("NavigationViewBackButton")); + } + } + static IUIElement Wait(Func query, Func satisfactory, string? timeoutMessage = null, From 5ffac96956dabf90cb7e0338b29dd4077e2b7b6a Mon Sep 17 00:00:00 2001 From: Anandhan Rajagopal <97146406+anandhan-rajagopal@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:55:41 +0530 Subject: [PATCH 3/4] Update AppiumApp.cs Refered the code from https://github.com/dotnet/maui/commit/9dab842bc5a145e745f8951dd760a22e44b966a3 --- src/TestUtils/src/UITest.Appium/AppiumApp.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/TestUtils/src/UITest.Appium/AppiumApp.cs b/src/TestUtils/src/UITest.Appium/AppiumApp.cs index 99160df665bc..91a0d3634940 100644 --- a/src/TestUtils/src/UITest.Appium/AppiumApp.cs +++ b/src/TestUtils/src/UITest.Appium/AppiumApp.cs @@ -90,7 +90,7 @@ public virtual IUIElement FindElement(IQuery query) #nullable disable public virtual IUIElement FindElementByText(string text) { - return AppiumQuery.ByXPath("//*[@text='" + text + "']").FindElement(this); + return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElement(this); } #nullable enable @@ -101,7 +101,7 @@ public virtual IReadOnlyCollection FindElements(string id) public virtual IReadOnlyCollection FindElementsByText(string text) { - return AppiumQuery.ByXPath("//*[@text='" + text + "']").FindElements(this); + return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElements(this); } public virtual IReadOnlyCollection FindElements(IQuery query) From 321de8247847b992c8dfe0cf75454ca7bd31ba91 Mon Sep 17 00:00:00 2001 From: Anandhan Rajagopal <97146406+anandhan-rajagopal@users.noreply.github.com> Date: Thu, 14 Nov 2024 15:38:14 +0530 Subject: [PATCH 4/4] Updated the fails message content --- .../TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs index 570ad8f95e6a..07907eb9ca98 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12320.cs @@ -1,4 +1,4 @@ -#if TEST_FAILS_ON_CATALYST // In Catalyst App.TapBackArrow() not working when override the back button icon of the navigation page. +#if TEST_FAILS_ON_CATALYST // In the Catalyst App, the TapBackArrow() function does not work when the back button icon is replaced with a new image on the navigation page. using NUnit.Framework; using UITest.Appium; using UITest.Core;