Skip to content

Commit

Permalink
added extensions class for NavigateBack
Browse files Browse the repository at this point in the history
  • Loading branch information
anandhan-rajagopal committed Nov 7, 2024
1 parent 7b55a47 commit f1ff61a
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 19 deletions.
6 changes: 2 additions & 4 deletions src/Controls/tests/TestCases.HostApp/Issues/TestShell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }
Expand Down
19 changes: 19 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1657,6 +1657,25 @@ public static IList<object> GetPerformanceData(this IApp app, string performance
throw new InvalidOperationException($"Could not get the performance data");
}

/// <summary>
/// Navigates back in the application by simulating a tap on the platform-specific back navigation button.
/// </summary>
/// <param name="app">Represents the main gateway to interact with an app.</param>
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<IUIElement?> query,
Func<IUIElement?, bool> satisfactory,
string? timeoutMessage = null,
Expand Down

0 comments on commit f1ff61a

Please sign in to comment.