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 - 11 #25855

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ int CommandCount

protected override void Init()
{
PressedLabel = new Label();
ReleasedLabel = new Label();
ClickedLabel = new Label();
CommandLabel = new Label();
PressedLabel = new Label { AutomationId = "PressedLabel" };
ReleasedLabel = new Label { AutomationId = "ReleasedLabel" };
ClickedLabel = new Label { AutomationId = "ClickedLabel" };
CommandLabel = new Label { AutomationId = "CommandLabel" };

var button = new Button
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public HeaderCell()
Height = 44;
var label = new Label { BackgroundColor = Colors.Pink };
label.SetBinding(Label.TextProperty, "GroupName");
label.SetBinding(Label.AutomationIdProperty, "GroupName");
View = label;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,12 @@ protected override void Init()
});

item2.Title = "Visible After Remove";
#pragma warning disable CS0618 // Type or member is obsolete
#pragma warning disable CS0612 // Type or member is obsolete
Device.BeginInvokeOnMainThread(() =>

MainThread.BeginInvokeOnMainThread(() =>
{
this.Items.Remove(item1);
});
#pragma warning restore CS0612 // Type or member is obsolete
#pragma warning restore CS0618 // Type or member is obsolete


}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#if MACCATALYST
using NUnit.Framework;
using NUnit.Framework;
using NUnit.Framework.Legacy;
using UITest.Appium;
using UITest.Core;
Expand All @@ -14,17 +13,15 @@ public Github1776(TestDevice testDevice) : base(testDevice)

public override string Issue => "Button Released not being triggered";

// [Test]
// [Category(UITestCategories.Button)]
// public void GitHub1776Test()
// {
// App.WaitForElement(q => q.Marked("TheButton"));
// App.Tap(q => q.Marked("TheButton"));

// Assert.AreEqual(1, _pressedCount, "Pressed should fire once per tap");
// Assert.AreEqual(1, _releasedCount, "Released should fire once per tap");
// Assert.AreEqual(1, _clickedCount, "Clicked should fire once per tap");
// Assert.AreEqual(1, _commandCount, "Command should fire once per tap");
// }
[Test]
[Category(UITestCategories.Button)]
public void GitHub1776Test()
{
App.WaitForElement("TheButton");
App.Tap("TheButton");
Assert.That(App.FindElement("PressedLabel").GetText(), Is.EqualTo("Pressed: 1"));
Assert.That(App.FindElement("ReleasedLabel").GetText(), Is.EqualTo("Released: 1"));
Assert.That(App.FindElement("ClickedLabel").GetText(), Is.EqualTo("Clicked: 1"));
Assert.That(App.FindElement("CommandLabel").GetText(), Is.EqualTo("Command: 1"));
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
#if TEST_FAILS_ON_CATALYST // In the Catalyst App, the TapBackArrow() function does not work when the back button icon is replaced with a new image on the navigation page.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use a compilation directive and use a custom query in Catalyst?

using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -12,13 +13,13 @@ public Issue12320(TestDevice testDevice) : base(testDevice)

public override string Issue => "[iOS] TabBarIsVisible = True/False doesn't work on Back Navigation When using BackButtonBehavior";

// Where does TapBackArrow come from?
// [Test]
// [Category(UITestCategories.Shell)]
// public void PopLogicExecutesWhenUsingBackButtonBehavior()
// {
// App.WaitForElement("TestReady");
// base.TapBackArrow();
// App.WaitForElement("Tab 1");
// }
}
[Test]
[Category(UITestCategories.Shell)]
public void PopLogicExecutesWhenUsingBackButtonBehavior()
{
App.WaitForElement("TestReady");
App.TapBackArrow();
App.WaitForElement("Tab 1");
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,12 @@ public Issue2953(TestDevice testDevice) : base(testDevice)

public override string Issue => "GroupHeaderCells disappear when item is removed from a group in ListView (iOS only) ";

// [Test]
// [Category(UITestCategories.ListView)]
// [FailsOnIOS]
// public void Issue2953Test()
// {
// App.Screenshot("I am at Issue 2953");
// App.WaitForElement(q => q.Marked("Header 3"));
// App.Screenshot("I see the Header 3");
// App.Tap(q => q.Marked("btnRemove"));
// App.WaitForElement(q => q.Marked("Header 3"));
// App.Screenshot("I still see the Header 3");
// }
[Test]
[Category(UITestCategories.ListView)]
public void Issue2953Test()
{
App.WaitForElement("Header 3");
App.Tap("btnRemove");
App.WaitForElement("Header 3");
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not impact in the test results etc, but could you leave the original test lines taking screenshots?
Like:
App.Screenshot("I still see the Header 3");

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ public Issue8008(TestDevice testDevice) : base(testDevice)

public override string Issue => "Removing Shell Item can cause Shell to try and set a MenuItem as the default visible item";

//[Test]
//[Category(UITestCategories.Shell)]
//[FailsOnIOS]
//public void RemovingShellItemCorrectlyPicksNextValidShellItemAsVisibleShellItem()
//{
// App.WaitForElement("Success");
//}
[Test]
[Category(UITestCategories.Shell)]
public void RemovingShellItemCorrectlyPicksNextValidShellItemAsVisibleShellItem()
{
App.WaitForElement("Success");
}
}
4 changes: 2 additions & 2 deletions src/TestUtils/src/UITest.Appium/AppiumApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public virtual IUIElement FindElement(IQuery query)
#nullable disable
public virtual IUIElement FindElementByText(string text)
{
return AppiumQuery.ByXPath("//*[@text='" + text + "']").FindElement(this);
return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElement(this);
}
#nullable enable

Expand All @@ -101,7 +101,7 @@ public virtual IReadOnlyCollection<IUIElement> FindElements(string id)

public virtual IReadOnlyCollection<IUIElement> FindElementsByText(string text)
{
return AppiumQuery.ByXPath("//*[@text='" + text + "']").FindElements(this);
return AppiumQuery.ByXPath("//*[@text='" + text + "' or @Name='" + text + "']").FindElements(this);
}

public virtual IReadOnlyCollection<IUIElement> FindElements(IQuery query)
Expand Down
20 changes: 20 additions & 0 deletions src/TestUtils/src/UITest.Appium/HelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,26 @@ 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 TapBackArrow(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
Loading