diff --git a/src/Controls/tests/TestCases.HostApp/Issues/TestShell.cs b/src/Controls/tests/TestCases.HostApp/Issues/TestShell.cs index b12a60f8cf52..6f210c4ad544 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/TestShell.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/TestShell.cs @@ -7,12 +7,10 @@ public abstract class TestShell : Shell #else protected const string FlyoutIconAutomationId = "OK"; #endif -#if IOS || MACCATALYST +#if __IOS__ || WINDOWS protected const string BackButtonAutomationId = "Back"; -#elif WINDOWS - protected const string BackButtonAutomationId = "NavigationViewBackButton"; #else - protected const string BackButtonAutomationId = "Navigate up"; + protected const string BackButtonAutomationId = "Navigate up"; #endif protected void IncreaseFlyoutItemsHeightSoUITestsCanClickOnThem() diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1024.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1024.cs index d75f5987ddd6..d3fc3b67ed5e 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1024.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue1024.cs @@ -22,11 +22,8 @@ public void Bugzilla1024Test() App.Tap("Push"); App.WaitForElement("ListView"); -#if ANDROID - App.Tap(AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc='Navigate up']")); -#else - App.Tap("NavigationViewBackButton"); -#endif + App.NavigateBack(); + } // At this point, the counter can be any value, but it's most likely not zero. diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12126.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12126.cs index 6c9f958c3933..b04866906ff5 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12126.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue12126.cs @@ -18,12 +18,7 @@ public Issue12126(TestDevice testDevice) : base(testDevice) public void NavigatingBackFromMultiplePushPagesChangesTabVisibilityCorrectly() { App.WaitForElement("TestReady"); -#if ANDROID - App.Tap(AppiumQuery.ByXPath("//android.widget.ImageButton[@content-desc='Navigate up']")); -#else - App.Tap(BackButtonAutomationId); -#endif - + App.NavigateBack(); #if WINDOWS App.WaitForElement("navViewItem"); #else diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs index b228710004e2..ab2dd7e87a2d 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/_IssuesUITest.cs @@ -11,12 +11,10 @@ public abstract class _IssuesUITest : UITest #else protected const string FlyoutIconAutomationId = "OK"; #endif -#if IOS || MACCATALYST +#if __IOS__ || WINDOWS protected const string BackButtonAutomationId = "Back"; -#elif WINDOWS - protected const string BackButtonAutomationId = "NavigationViewBackButton"; #else - protected const string BackButtonAutomationId = "Navigate up"; + protected const string BackButtonAutomationId = "Navigate up"; #endif public _IssuesUITest(TestDevice device) : base(device) { } diff --git a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs index 7790e2134d38..a93bf1fcee3e 100644 --- a/src/TestUtils/src/UITest.Appium/HelperExtensions.cs +++ b/src/TestUtils/src/UITest.Appium/HelperExtensions.cs @@ -1657,6 +1657,25 @@ 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 NavigateBack(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,