Skip to content

Commit

Permalink
Enabled 24th set of XamarinUITests into Appium (#22) (#26220)
Browse files Browse the repository at this point in the history
* Migrated the Issue12685, Issue2809 and Issue2894

* Updated the migrated issues

* Updated migrated code changes

* resolved random test failures

---------

Co-authored-by: nivetha-nagalingam <nivetha.nagalingam@syncfusion.com>
  • Loading branch information
anandhan-rajagopal and nivetha-nagalingam authored Nov 29, 2024
1 parent 37a2d9d commit 6cd3d86
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 92 deletions.
12 changes: 6 additions & 6 deletions src/Controls/tests/TestCases.HostApp/Issues/XFIssue/Issue2809.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
namespace Maui.Controls.Sample.Issues;

using Maui.Controls.Sample.Issues;

[Issue(IssueTracker.Github, 2809, "Secondary ToolbarItems cause app to hang during PushAsync", PlatformAffected.iOS)]
public class Issue2809 : TestContentPage
public class Issue2809 : TestNavigationPage
{
protected override void Init()
{
ToolbarItems.Add(new ToolbarItem("Item 1", string.Empty,
var contentPage = new ContentPage();
contentPage.ToolbarItems.Add(new ToolbarItem("Item 1", string.Empty,
DummyAction, ToolbarItemOrder.Secondary));

ToolbarItems.Add(new ToolbarItem("Item 2", string.Empty,
contentPage.ToolbarItems.Add(new ToolbarItem("Item 2", string.Empty,
DummyAction, ToolbarItemOrder.Secondary));
Navigation.PushAsync(contentPage);
}

public void DummyAction()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,28 @@ namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue12685 : _IssuesUITest
{
const string StatusLabelId = "StatusLabelId";
const string ResetStatus = "Path touch event not fired, touch path above.";
const string ClickedStatus = "Path was clicked, click reset button to start over.";
public Issue12685(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "[iOs][Bug] TapGestureRecognizer in Path does not work on iOS";

// [Test]
// [Category(UITestCategories.Shape)]
// [FailsOnIOS]
// public void ShapesPathReceiveGestureRecognizers()
// {
// var testLabel = App.WaitForFirstElement(StatusLabelId);
// Assert.AreEqual(ResetStatus, testLabel.ReadText());
// var testPath = App.WaitForFirstElement(PathId);
// var pathRect = testPath.Rect;
// App.TapCoordinates(pathRect.X + 1, pathRect.Y + 1);
// Assert.AreEqual(ClickedStatus, App.WaitForFirstElement(StatusLabelId).ReadText());
// }
[Test]
[Category(UITestCategories.Shape)]
public void ShapesPathReceiveGestureRecognizers()
{
var testLabel = App.WaitForFirstElement(StatusLabelId);
Assert.That(testLabel.ReadText(), Is.EqualTo(ResetStatus));
var labelRect = App.WaitForFirstElement(StatusLabelId).GetRect(); // Path element not able get via automationid so getting the rect of the label calculated points to tap on the path
#if MACCATALYST // TapCoordinates is not working on MacCatalyst Issue: https://github.com/dotnet/maui/issues/19754
App.ClickCoordinates(labelRect.X + 3, labelRect.Y - 10);
#else
App.TapCoordinates(labelRect.X + 3, labelRect.Y - 10);
#endif
App.WaitForElement(StatusLabelId);
Assert.That(testLabel.ReadText(), Is.EqualTo(ClickedStatus));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,11 @@ public Issue2809(TestDevice testDevice) : base(testDevice)

public override string Issue => "Secondary ToolbarItems cause app to hang during PushAsync";

// [Test]
// [Category(UITestCategories.DisplayAlert)]
// [FailsOnIOS]
// public void TestPageDoesntCrash()
// {
// ShouldShowMenu();
// App.Tap(c => c.Marked("Item 1"));
// App.Screenshot("Didn't crash");
// }

// void ShouldShowMenu()
// {
// #if ANDROID
// //show secondary menu
// App.TapOverflowMenuButton();
// #elif WINDOWS
// App.Tap ("MoreButton");
// #endif
// }
[Test]
[Category(UITestCategories.ToolbarItem)]
public void TestPageDoesntCrash()
{
App.TapMoreButton();
App.Tap("Item 1");
}
}
Original file line number Diff line number Diff line change
@@ -1,73 +1,68 @@
using NUnit.Framework;
using System.Drawing;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue2894 : _IssuesUITest
{
const string kGesture1 = "Sentence 1: ";
const string kGesture2 = "Sentence 2: ";
const string kLabelAutomationId = "kLabelAutomationId";

public Issue2894(TestDevice testDevice) : base(testDevice)
{
}

public override string Issue => "Gesture Recognizers added to Span after it's been set to FormattedText don't work and can cause an NRE";

// [FailsOnAndroid]
// [FailsOnIOS]
// [Test]
// [Category(UITestCategories.Gestures)]
// public void VariousSpanGesturePermutation()
// {
// App.WaitForElement($"{kGesture1}0");
// App.WaitForElement($"{kGesture2}0");
// var labelId = App.WaitForElement(kLabelAutomationId);
// var target = labelId.First().Rect;


// for (int i = 1; i < 5; i++)
// {
// App.Tap($"TestSpan{i}");

// // These tap retries work around a Tap Coordinate bug
// // with Xamarin.UITest >= 3.0.7
// int tapAttempts = 0;
// do
// {
// App.TapCoordinates(target.X + 5, target.Y + 5);
// if (tapAttempts == 4)
// App.WaitForElement($"{kGesture1}{i}");

// tapAttempts++;
// } while (App.Query($"{kGesture1}{i}").Length == 0);

// tapAttempts = 0;

// do
// {
// #if WINDOWS
// App.TapCoordinates(target.X + target.Width - 10, target.Y + 2);
// #else
// App.TapCoordinates(target.X + target.CenterX, target.Y + 2);
// #endif
// if (tapAttempts == 4)
// App.WaitForElement($"{kGesture1}{i}");

// tapAttempts++;

// } while (App.Query($"{kGesture2}{i}").Length == 0);
// }
[Test]
[Category(UITestCategories.Gestures)]
public void VariousSpanGesturePermutation()
{
App.WaitForElement($"{kGesture1}0");
App.WaitForElement($"{kGesture2}0");
var labelId = App.WaitForElement(kLabelAutomationId);
var target = labelId.GetRect();

for (int i = 1; i < 5; i++)
{
App.Tap($"TestSpan{i}");
App.WaitForElement($"{kGesture1}{i-1}");
App.WaitForElement(kLabelAutomationId);
PerformGestureActionForFirstSpan(target);
PerformGestureActionForSecondSpan(target);
}

App.Tap($"TestSpan5");
PerformGestureActionForFirstSpan(target);
PerformGestureActionForSecondSpan(target);
App.WaitForElement($"{kGesture1}4");
App.WaitForElement($"{kGesture2}4");
}

void PerformGestureAction(float x, float y)
{
#if MACCATALYST // TapCoordinates is not working on MacCatalyst Issue: https://github.com/dotnet/maui/issues/19754
App.ClickCoordinates(x, y);
#else
App.TapCoordinates(x, y);
#endif
}

// App.Tap($"TestSpan5");
// App.TapCoordinates(target.X + 5, target.Y + 5);
void PerformGestureActionForFirstSpan(Rectangle target)
{
PerformGestureAction(target.X + 5, target.Y + 5);
}

// #if WINDOWS
// App.TapCoordinates(target.X + target.Width - 10, target.Y + 2);
// #else
// App.TapCoordinates(target.X + target.CenterX, target.Y + 2);
// #endif
void PerformGestureActionForSecondSpan(Rectangle target)
{
#if ANDROID // Calculate points vary on Android and other platforms.
App.TapCoordinates(target.X + target.Width /2, target.Y + 2);
#else
PerformGestureAction(target.X + target.Width - 10, target.Y + 2);
#endif

// App.WaitForElement($"{kGesture1}4");
// App.WaitForElement($"{kGesture2}4");
// }
}
}
17 changes: 17 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,23 @@ public static void TapBackArrow(this IApp app, string customBackButtonIdentifier
}
}

/// <summary>
/// Taps the "More" button in the app, with platform-specific logic for Android and Windows.
/// This method does not currently support iOS and macOS platforms, where the "More" button is not shown.
/// </summary>
/// <param name="app">Represents the main gateway to interact with an app.</param>
public static void TapMoreButton(this IApp app)
{
if (app is AppiumAndroidApp)
{
app.Tap(AppiumQuery.ByXPath("//android.widget.ImageView[@content-desc=\"More options\"]"));
}
else if (app is AppiumWindowsApp)
{
app.Tap(AppiumQuery.ByAccessibilityId("MoreButton"));
}
}

static IUIElement Wait(Func<IUIElement?> query,
Func<IUIElement?, bool> satisfactory,
string? timeoutMessage = null,
Expand Down

0 comments on commit 6cd3d86

Please sign in to comment.