Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Testing] Enabling ported UITests from Xamarin.UITests to Appium - 23 #26219

Merged
merged 8 commits into from
Dec 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -5,77 +5,90 @@
namespace Microsoft.Maui.TestCases.Tests.Issues;
public class FlyoutBehaviorShell : _IssuesUITest
{
const string title = "Basic Test";
const string FlyoutItem = "Flyout Item";
const string EnableFlyoutBehavior = "EnableFlyoutBehavior";
const string DisableFlyoutBehavior = "DisableFlyoutBehavior";
const string LockFlyoutBehavior = "LockFlyoutBehavior";
const string OpenFlyout = "OpenFlyout";
const string EnableBackButtonBehavior = "EnableBackButtonBehavior";
const string DisableBackButtonBehavior = "DisableBackButtonBehavior";
public FlyoutBehaviorShell(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Shell Flyout Behavior";

// [FailsOnAndroidWhenRunningOnXamarinUITest]
// [Test]
// [Category(UITestCategories.Shell)]
// public void FlyoutTests()
// {
// // Flyout is visible
// App.WaitForElement(EnableFlyoutBehavior);

// // Starting shell out as disabled correctly disables flyout
// App.WaitForNoElement(FlyoutIconAutomationId, "Flyout Icon Visible on Startup");
// ShowFlyout(usingSwipe: true, testForFlyoutIcon: false);
// App.WaitForNoElement(FlyoutItem, "Flyout Visible on Startup");

// // Enable Flyout Test
// App.Tap(EnableFlyoutBehavior);
// ShowFlyout(usingSwipe: true);
// App.WaitForElement(FlyoutItem, "Flyout Not Visible after Enabled");
// App.Tap(FlyoutItem);
[Test]
[Category(UITestCategories.Shell)]
public void FlyoutTests()
{
// Flyout is visible
App.WaitForElement(EnableFlyoutBehavior);
#if !MACCATALYST && !WINDOWS //Swipe Options for Shell are not applicable for Desktop Platforms.
// Starting shell out as disabled correctly disables flyout
App.WaitForNoElement(FlyoutIconAutomationId, "Flyout Icon Visible on Startup");
App.ShowFlyout(usingSwipe: true, waitForFlyoutIcon: false);
App.WaitForNoElement(FlyoutItem, "Flyout Visible on Startup");

// // Flyout Icon is not visible but you can still swipe open
// App.Tap(DisableFlyoutBehavior);
// App.WaitForNoElement(FlyoutIconAutomationId, "Flyout Icon Visible after being Disabled");
// ShowFlyout(usingSwipe: true, testForFlyoutIcon: false);
// App.WaitForNoElement(FlyoutItem, "Flyout Visible after being Disabled");
// Enable Flyout Test
App.Tap(EnableFlyoutBehavior);
App.ShowFlyout(usingSwipe: true);
App.WaitForElement(FlyoutItem, "Flyout Not Visible after Enabled");
App.Tap(FlyoutItem);

// Flyout Icon is not visible but you can still swipe open
App.Tap(DisableFlyoutBehavior);
App.WaitForNoElement(FlyoutIconAutomationId, "Flyout Icon Visible after being Disabled");
App.ShowFlyout(usingSwipe: true, waitForFlyoutIcon: false);
App.WaitForNoElement(FlyoutItem, "Flyout Visible after being Disabled");

// // enable flyout and make sure disabling back button behavior doesn't hide icon
// App.Tap(EnableFlyoutBehavior);
// App.WaitForElement(FlyoutIconAutomationId);
// App.Tap(DisableBackButtonBehavior);
// ShowFlyout(usingSwipe: true);
// App.WaitForElement(FlyoutItem, "Flyout swipe not working after Disabling Back Button Behavior");
// App.Tap(FlyoutItem);

// // make sure you can still open flyout via code
// App.Tap(EnableFlyoutBehavior);
// App.Tap(EnableBackButtonBehavior);
// App.Tap(OpenFlyout);
// App.WaitForElement(FlyoutItem, "Flyout not opening via code");
// App.Tap(FlyoutItem);
// enable flyout and make sure disabling back button behavior doesn't hide icon
App.Tap(EnableFlyoutBehavior);
App.WaitForFlyoutIcon();
App.Tap(DisableBackButtonBehavior);
App.ShowFlyout(usingSwipe: true);
App.WaitForElement(FlyoutItem, "Flyout swipe not working after Disabling Back Button Behavior");
App.Tap(FlyoutItem);
#endif
// // make sure you can still open flyout via code
App.Tap(EnableFlyoutBehavior);
App.Tap(EnableBackButtonBehavior);
App.Tap(OpenFlyout);
App.WaitForElement(FlyoutItem, "Flyout not opening via code");
App.Tap(FlyoutItem);

// // make sure you can still open flyout via code if flyout behavior is disabled
// App.Tap(DisableFlyoutBehavior);
// App.Tap(EnableBackButtonBehavior);
// App.Tap(OpenFlyout);
// App.WaitForElement(FlyoutItem, "Flyout not opening via code when flyout behavior disabled");
// App.Tap(FlyoutItem);
#if !IOS && !MACCATALYST // When DisableFlyoutBehavior is set, flyout items become inaccessible via inspection tools, leading to timeout exceptions on both iOS and Catalyst.

// make sure you can still open flyout via code if flyout behavior is disabled
App.Tap(DisableFlyoutBehavior);
App.Tap(EnableBackButtonBehavior);
App.Tap(OpenFlyout);
App.WaitForElement(FlyoutItem, "Flyout not opening via code when flyout behavior disabled");
App.Tap(FlyoutItem);
#endif

// // make sure you can still open flyout via code if back button behavior is disabled
// App.Tap(EnableFlyoutBehavior);
// App.Tap(DisableBackButtonBehavior);
// App.Tap(OpenFlyout);
// App.WaitForElement(FlyoutItem, "Flyout not opening via code when back button behavior is disabled");
// App.Tap(FlyoutItem);
// make sure you can still open flyout via code if back button behavior is disabled
App.Tap(EnableFlyoutBehavior);
App.Tap(DisableBackButtonBehavior);
App.Tap(OpenFlyout);
App.WaitForElement(FlyoutItem, "Flyout not opening via code when back button behavior is disabled");
App.Tap(FlyoutItem);

// }
}

// [Test]
// public void WhenFlyoutIsLockedButtonsAreStillVisible()
// {
// // FlyoutLocked ensure that the flyout and buttons are still visible
// App.Tap(EnableBackButtonBehavior);
// App.Tap(LockFlyoutBehavior);
// App.WaitForElement(title, "Flyout Locked hiding content");
// App.Tap(EnableFlyoutBehavior);
// App.WaitForNoElement(FlyoutItem);
// }
[Test]
[Category(UITestCategories.Shell)]
public void WhenFlyoutIsLockedButtonsAreStillVisible()
{
// FlyoutLocked ensure that the flyout and buttons are still visible
App.WaitForElement(EnableBackButtonBehavior);
App.Tap(EnableBackButtonBehavior);
App.Tap(LockFlyoutBehavior);
App.WaitForElement(title,"Flyout Locked hiding content");
App.Tap(EnableFlyoutBehavior);
App.WaitForNoElement(FlyoutItem);
}
}
54 changes: 54 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1869,6 +1869,60 @@ public static void WaitForElementTillPageNavigationSettled(this IApp app, IQuery

app.WaitForElement(query, timeout: timeout);
}
/// <summary>
/// Waits for the flyout icon to appear in the app.
/// </summary>
/// <param name="app">The IApp instance representing the application.</param>
/// <param name="automationId">The automation ID of the flyout icon (default is an empty string).</param>
/// <param name="isShell">Indicates whether the app is using Shell navigation (default is true).</param>
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.WaitForElement(AppiumQuery.ByAccessibilityId("TogglePaneButton"));
}
else
{
app.WaitForElement(automationId);
}
}
}
}

/// <summary>
/// Shows the flyout menu in the app.
/// </summary>
/// <param name="app">The IApp instance representing the application.</param>
/// <param name="automationId">The automation ID of the flyout icon (default is an empty string).</param>
/// <param name="usingSwipe">Indicates whether to use swipe gesture to open the flyout (default is false).</param>
/// <param name="waitForFlyoutIcon">Indicates whether to wait for the flyout icon before showing the flyout (default is true).</param>
/// <param name="isShell">Indicates whether the app is using Shell navigation (default is true).</param>
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);
}
}

/// <summary>
/// Waits for the flyout icon to appear in the app.
Expand Down
Loading