Skip to content

Commit 0622a37

Browse files
authored
[Testing] Fixed test case failure 28485 (#28644)
1 parent 5a4e1f1 commit 0622a37

File tree

4 files changed

+48
-5
lines changed

4 files changed

+48
-5
lines changed

src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/Issue28485.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void SwipeBackGestureShouldNavigateOnce()
2424
App.Click("GotoPage3");
2525
App.WaitForElement("Page3Label");
2626
App.Click("Page3Label");
27-
App.InteractivePopGesture();
27+
App.SwipeBackNavigation();
2828
App.WaitForElement("Page2Label");
2929
App.WaitForNoElement("GotoPage2");
3030
}

src/TestUtils/src/UITest.Appium/Actions/AppiumAndroidSpecificActions.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class AppiumAndroidSpecificActions : ICommandExecutionGroup
1414
const string ToggleSystemAnimationsCommand = "toggleSystemAnimations";
1515
const string GetSystemBarsCommand = "getSystemBars";
1616
const string ToggleSecondaryToolbarItemsCommand = "toggleSecondaryToolbarItems";
17+
const string CheckIfGestureNavigationIsEnabledCommand = "checkIfGestureNavigationIsEnabled";
1718

1819
readonly AppiumApp _appiumApp;
1920

@@ -26,6 +27,7 @@ public class AppiumAndroidSpecificActions : ICommandExecutionGroup
2627
ToggleSystemAnimationsCommand,
2728
GetSystemBarsCommand,
2829
ToggleSecondaryToolbarItemsCommand,
30+
CheckIfGestureNavigationIsEnabledCommand,
2931
};
3032

3133
public AppiumAndroidSpecificActions(AppiumApp appiumApp)
@@ -49,6 +51,7 @@ public CommandResponse Execute(string commandName, IDictionary<string, object> p
4951
ToggleSystemAnimationsCommand => ToggleSystemAnimations(parameters),
5052
GetSystemBarsCommand => GetSystemBars(parameters),
5153
ToggleSecondaryToolbarItemsCommand => ToggleSecondaryToolbarItems(parameters),
54+
CheckIfGestureNavigationIsEnabledCommand => CheckIfGestureNavigationIsEnabled(parameters),
5255
_ => CommandResponse.FailedEmptyResponse,
5356
};
5457
}
@@ -91,6 +94,18 @@ CommandResponse ToggleWifi(IDictionary<string, object> parameters)
9194
return CommandResponse.FailedEmptyResponse;
9295
}
9396

97+
CommandResponse CheckIfGestureNavigationIsEnabled(IDictionary<string, object> parameters)
98+
{
99+
if (_appiumApp.Driver is AndroidDriver androidDriver)
100+
{
101+
var result = ShellHelper.ExecuteShellCommandWithOutput("adb shell cmd overlay list");
102+
var isEnabled = result.Contains("[x] com.android.internal.systemui.navbar.gestural", StringComparison.OrdinalIgnoreCase);
103+
return new CommandResponse(isEnabled, CommandResponseResult.Success);
104+
}
105+
106+
return CommandResponse.FailedEmptyResponse;
107+
}
108+
94109
CommandResponse GetPerformanceData(IDictionary<string, object> parameters)
95110
{
96111
if (_appiumApp.Driver is AndroidDriver androidDriver)

src/TestUtils/src/UITest.Appium/HelperExtensions.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,11 +1764,11 @@ public static void Shake(this IApp app)
17641764
}
17651765

17661766
/// <summary>
1767-
/// Triggers the interactive pop gesture, simulating the default swipe-back navigation.
1767+
/// Triggers the SwipeBackNavigation, simulating the default swipe-back navigation.
17681768
/// </summary>
17691769
/// <param name="app">Represents the main gateway to interact with an app.</param>
1770-
/// /// <exception cref="InvalidOperationException">InteractivePopGesture is only supported on <see cref="AppiumIOSApp"/> and <see cref="AppiumAndroidApp"/>.</exception>
1771-
public static void InteractivePopGesture(this IApp app)
1770+
/// /// <exception cref="InvalidOperationException">SwipeBackNavigation is only supported on <see cref="AppiumIOSApp"/> and <see cref="AppiumAndroidApp"/>.</exception>
1771+
public static void SwipeBackNavigation(this IApp app)
17721772
{
17731773
if (app is not AppiumIOSApp && app is not AppiumAndroidApp)
17741774
{
@@ -1781,7 +1781,11 @@ public static void InteractivePopGesture(this IApp app)
17811781
}
17821782
else if (app is AppiumAndroidApp)
17831783
{
1784-
SwipeLeftToRight(app);
1784+
var response = app.CommandExecutor.Execute("checkIfGestureNavigationIsEnabled", new Dictionary<string, object>());
1785+
if (response?.Value is bool gestureNavigationIsEnabled && gestureNavigationIsEnabled)
1786+
SwipeLeftToRight(app);
1787+
else
1788+
Back(app);
17851789
}
17861790
}
17871791

src/TestUtils/src/UITest.Appium/ShellHelper.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,30 @@ public static void ExecuteShellCommand(string command)
2323
process.WaitForExit();
2424
}
2525

26+
public static string ExecuteShellCommandWithOutput(string command)
27+
{
28+
var shell = GetShell();
29+
var shellArgument = GetShellArgument(shell, command);
30+
31+
var processInfo = new ProcessStartInfo(shell, shellArgument)
32+
{
33+
CreateNoWindow = true,
34+
UseShellExecute = false,
35+
RedirectStandardOutput = true,
36+
RedirectStandardError = true
37+
};
38+
39+
using var process = new Process { StartInfo = processInfo };
40+
process.Start();
41+
42+
string output = process.StandardOutput.ReadToEnd();
43+
string error = process.StandardError.ReadToEnd();
44+
45+
process.WaitForExit();
46+
47+
return string.IsNullOrWhiteSpace(output) ? error : output;
48+
}
49+
2650
internal static string GetShell()
2751
{
2852
if (Environment.OSVersion.Platform == PlatformID.Win32NT)

0 commit comments

Comments
 (0)