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 - 10 #25847

Open
wants to merge 5 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 @@ -65,11 +65,13 @@ public TestCell()
{
var menuItem = new MenuItem();
menuItem.SetBinding(MenuItem.TextProperty, "ItemText");
menuItem.SetBinding(MenuItem.AutomationIdProperty, "ItemText");
ContextActions.Add(menuItem);


var textLabel = new Label();
textLabel.SetBinding(Label.TextProperty, "Text");
textLabel.SetBinding(Label.AutomationIdProperty, "Text");
View = textLabel;
}
}
3 changes: 2 additions & 1 deletion src/Controls/tests/TestCases.HostApp/Issues/Issue7534.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected override void Init()
var labelDescription = new Label
{
Text = "If you opened this page, the app didn't crash and you can read three lines in the label above, this test has passed",
VerticalOptions = LayoutOptions.StartAndExpand
VerticalOptions = LayoutOptions.StartAndExpand,
AutomationId = "Success"
};
#pragma warning restore CS0618 // Type or member is obsolete

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public class MainPageCode : TabbedPage
{
public MainPageCode()
{
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = "add1" });
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = $"{add2}" });
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = $"{add3}" });
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = "add1" , AutomationId = "add1" });
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = $"{add2}", AutomationId = add2 });
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = $"{add3}", AutomationId = add3 });
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = "reload" });
ToolbarItems.Add(new Microsoft.Maui.Controls.ToolbarItem() { Text = "visible" });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async void OnPageAppearing(object sender, EventArgs e)


await Task.Delay(1);
layout.AddLogicalChild(
layout.Children.Add(
new Label()
{
Text = "If app hasn't crashed test has succeeded",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void Init()
"event should have been raised twice. If not, this test has failed."
};

_eventRaisedCount = new Label();
_eventRaisedCount = new Label() { AutomationId = "SelectionChangedCount" };

var layout = new StackLayout();
var cv = new CollectionView();
Expand All @@ -30,9 +30,9 @@ protected override void Init()

cv.SelectionChanged += SelectionChangedHandler;

layout.AddLogicalChild(instructions);
layout.AddLogicalChild(_eventRaisedCount);
layout.AddLogicalChild(cv);
layout.Children.Add(instructions);
layout.Children.Add(_eventRaisedCount);
layout.Children.Add(cv);

Content = layout;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,31 +1,26 @@
#if IOS
using NUnit.Framework;
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Bugzilla56710 : _IssuesUITest
{
const string Success = "Success";
const string BtnAdd = "btnAdd";

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

public override string Issue => "Multi-item add in INotifyCollectionChanged causes a NSInternalInconsistencyException in bindings on iOS";
public override string Issue => "ContextActionsCell.OnMenuItemPropertyChanged throws NullReferenceException";

// [Test]
// [Category(UITestCategories.ListView)]
// [Category(UITestCategories.Compatibility)]
// [FailsOnIOSWhenRunningOnXamarinUITest]
// [FailsOnMacWhenRunningOnXamarinUITest]
// public void Bugzilla56771Test()
// {
// App.WaitForElement(BtnAdd);
// App.Tap(BtnAdd);
// App.WaitForNoElement(Success);
// }
}
#endif
[Test]
[Category(UITestCategories.ListView)]
[Category(UITestCategories.Compatibility)]
public void Bugzilla56710Test()
{
App.WaitForElement("Go to Test Page");
App.Tap("Go to Test Page");
App.WaitForElement("Item 3");
App.TapBackArrow();
App.WaitForElement("Go to Test Page");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,14 @@ public Issue3390(TestDevice testDevice) : base(testDevice)

public override string Issue => "Crash or incorrect behavior with corner radius 5";

// [Test]
// [Category(UITestCategories.Button)]
// [Category(UITestCategories.Compatibility)]
// [FailsOnIOSWhenRunningOnXamarinUITest]
// [FailsOnMacWhenRunningOnXamarinUITest]
// public void Issue3390Test()
// {
// App.WaitForElement("TestButton");
// App.Tap("TestButton");
// App.WaitForNoElement("Success");
// }
[Test]
[Category(UITestCategories.Button)]
[Category(UITestCategories.Compatibility)]
public void Issue3390Test()
{
App.WaitForElement("TestButton");
App.Tap("TestButton");
Assert.That(App.FindElement("TestButton").GetText(), Is.EqualTo("Success"));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#if ANDROID
#if TEST_FAILS_ON_ANDROID // Getting Java.Lang.IndexOutOfBoundsException on Android (https://github.com/dotnet/maui/issues/25836)
using NUnit.Framework;
jsuarezruiz marked this conversation as resolved.
Show resolved Hide resolved
using UITest.Appium;
using UITest.Core;

namespace Microsoft.Maui.TestCases.Tests.Issues
Expand All @@ -12,18 +13,16 @@ public Issue7534(TestDevice testDevice) : base(testDevice)

public override string Issue => "Span with tail truncation and paragraph breaks with Java.Lang.IndexOutOfBoundsException";

// Crash after navigation
/*

[Test]
[Category(UITestCategories.Label)]
[Category(UITestCategories.Compatibility)]
[FailsOnAndroidWhenRunningOnXamarinUITest]
public void ExpectingPageNotToBreak()
{
App.Screenshot("Test passed, label is showing as it should!");
App.WaitForElement("Success");
//if it doesn't crash, we're good.
}
*/

}
}
#endif
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#if MACCATALYST
#if TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_CATALYST // Need to Implement App.PressEnter() for Catalyst and Windows.
using NUnit.Framework;
Copy link
Contributor

Choose a reason for hiding this comment

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

using NUnit.Framework.Legacy;
using UITest.Appium;
Expand All @@ -14,18 +14,15 @@ public Github1650(TestDevice testDevice) : base(testDevice)

public override string Issue => "[macOS] Completed event of Entry raised on Tab key";

// [Test]
// [Category(UITestCategories.Entry)]
// public void GitHub1650Test()
// {
// App.WaitForElement(q => q.Marked("CompletedTargetEntry"));
// App.Tap(q => q.Marked("CompletedTargetEntry"));

// Assert.AreEqual(0, _completedCount, "Completed should not have been fired");

// App.PressEnter();

// Assert.AreEqual(1, _completedCount, "Completed should have been fired once");
// }
[Test]
[Category(UITestCategories.Entry)]
public void GitHub1650Test()
{
App.WaitForElement("CompletedTargetEntry");
App.Tap("CompletedTargetEntry");
Assert.That(App.FindElement("CompletedCountLabel").GetText(), Is.EqualTo("Completed count: 0"));
App.PressEnter();
Assert.That(App.FindElement("CompletedCountLabel").GetText(), Is.EqualTo("Completed count: 1"));
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,19 @@ namespace Microsoft.Maui.TestCases.Tests.Issues;

public class Issue1342 : _IssuesUITest
{
const string Success = "Success";

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

public override string Issue => "[iOS] ListView throws Exception on ObservableCollection.Add/Remove for non visible list view";

// [Test]
// [Category(UITestCategories.ListView)]
// [Ignore("Fails sometimes - needs a better test")]
// public void AddingItemsToNonVisibleListViewDoesntCrash()
// {
// App.Tap(add2);
// App.Tap(add3);
// App.WaitForElement(success);
// }
[Test]
[Category(UITestCategories.ListView)]
public void AddingItemsToNonVisibleListViewDoesntCrash()
{
App.Tap("add2");
App.Tap("add3");
App.WaitForElement("add1");
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
#if TEST_FAILS_ON_CATALYST // Getting OpenQA.Selenium.InvalidSelectorException on Catalyst Line No: 20.
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -12,10 +13,11 @@ public Issue6484(TestDevice testDevice) : base(testDevice)

public override string Issue => "[iOS] Shell - Go back two pages crashes the app with a NullReferenceException";

//[Test]
//[Category(UITestCategories.Shell)]
//public void RemovingIntermediatePagesBreaksShell()
//{
// App.WaitForElement("Success");
//}
}
[Test]
[Category(UITestCategories.Shell)]
public void RemovingIntermediatePagesBreaksShell()
{
App.WaitForElement("Success");
}
}
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NUnit.Framework;
#if TEST_FAILS_ON_CATALYST // Need to fix the issue on Catalyst (https://github.com/dotnet/maui/issues/25826)
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;

Expand All @@ -13,14 +14,14 @@ public Issue8203(TestDevice testDevice) : base(testDevice)
public override string Issue => "CollectionView fires SelectionChanged x (number of items selected +1) times, while incrementing SelectedItems from 0 " +
"to number of items each time";

//[Test]
//[Category(UITestCategories.CollectionView)]
//[FailsOnIOS]
//public void SelectionChangedShouldBeRaisedOnceWhenSelectionChanges()
//{
// App.WaitForElement("one");
// App.Tap("one");
// App.Tap("two");
// App.WaitForElement("SelectionChanged has been raised 2 times.");
//}
}
[Test]
[Category(UITestCategories.CollectionView)]
public void SelectionChangedShouldBeRaisedOnceWhenSelectionChanges()
{
App.WaitForElement("one");
App.Tap("one");
App.Tap("two");
Assert.That(App.FindElement("SelectionChangedCount").GetText(), Is.EqualTo("SelectionChanged has been raised 2 times."));
}
}
#endif
6 changes: 3 additions & 3 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 Expand Up @@ -155,4 +155,4 @@ public void Dispose()
_driver?.Dispose();
}
}
}
}
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