[Testing] Enabling ported UITests from Xamarin.UITests to Appium - 8 (#25814)

* Migrated the Issue2740 and ListViewNRE (#1)

* Migrated the Issue2740 and ListViewNRE

* Migrated the Issue1355 and Issue2923

* Feedback addressed

---------

Co-authored-by: nivetha-nagalingam <nivetha.nagalingam@syncfusion.com>

* optimized the test code changes

---------

Co-authored-by: nivetha-nagalingam <nivetha.nagalingam@syncfusion.com>
This commit is contained in:
Anandhan Rajagopal 2024-11-13 22:22:32 +05:30 коммит произвёл GitHub
Родитель 353f1a3064
Коммит 0af4a9a882
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
9 изменённых файлов: 63 добавлений и 105 удалений

Просмотреть файл

@ -23,7 +23,7 @@
{ {
var page = new ContentPage var page = new ContentPage
{ {
Content = new Label { Text = Success }, Content = new Label { AutomationId = Success , Text = Success },
Title = $"CreatePage Iteration: {_runCount}" Title = $"CreatePage Iteration: {_runCount}"
}; };

Просмотреть файл

@ -1,40 +0,0 @@
namespace Maui.Controls.Sample.Issues;
[Issue(IssueTracker.Github, 1355, "Setting Main Page in quick succession causes crash on Android", PlatformAffected.Android, issueTestNumber: 1)]
public class Issue1355_Forms : TestContentPage
{
int _runCount = 0;
int _maxRunCount = 2;
const string Success = "Success";
protected override void Init()
{
Appearing += OnAppearing;
}
private void OnAppearing(object o, EventArgs eventArgs)
{
Application.Current.MainPage = CreatePage();
}
ContentPage CreatePage()
{
var page = new ContentPage
{
Content = new Label { Text = Success, AutomationId = Success },
Title = $"CreatePage Iteration: {_runCount}"
};
page.Appearing += (sender, args) =>
{
_runCount += 1;
if (_runCount <= _maxRunCount)
{
Application.Current.MainPage = new NavigationPage(CreatePage());
}
};
return page;
}
}

Просмотреть файл

@ -27,6 +27,20 @@ public class Issue2740 : TestFlyoutPage
{ {
var listview = new ListView(); var listview = new ListView();
listview.ItemsSource = new List<string> { "1", "2" }; listview.ItemsSource = new List<string> { "1", "2" };
listview.ItemTemplate = new DataTemplate(() =>
{
var label = new Label();
label.SetBinding(Label.TextProperty, ".");
label.SetBinding(Label.AutomationIdProperty, new Binding("."));
var viewCell = new ViewCell
{
View = label
};
return viewCell;
});
listview.ItemTapped += OnItemTapped; listview.ItemTapped += OnItemTapped;
Content = listview; Content = listview;
Title = "Unit List"; Title = "Unit List";

Просмотреть файл

@ -12,6 +12,20 @@ public class ListViewNRE : TestContentPage
ItemsSource = Enumerable.Range(0, 10) ItemsSource = Enumerable.Range(0, 10)
}; };
listView.ItemTemplate = new DataTemplate(() =>
{
var label = new Label();
label.SetBinding(Label.TextProperty, ".");
label.SetBinding(Label.AutomationIdProperty, new Binding("."));
var viewCell = new ViewCell
{
View = label
};
return viewCell;
});
listView.ItemSelected += ListView_ItemSelected; listView.ItemSelected += ListView_ItemSelected;
Content = listView; Content = listView;
@ -19,6 +33,6 @@ public class ListViewNRE : TestContentPage
void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e) void ListView_ItemSelected(object sender, SelectedItemChangedEventArgs e)
{ {
Content = new Label { Text = Success }; Content = new Label { AutomationId = Success , Text = Success };
} }
} }

Просмотреть файл

@ -1,5 +1,4 @@
#if ANDROID using NUnit.Framework;
using NUnit.Framework;
using UITest.Appium; using UITest.Appium;
using UITest.Core; using UITest.Core;
@ -7,7 +6,6 @@ namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue1355 : _IssuesUITest public class Issue1355 : _IssuesUITest
{ {
const string Success = "Success";
public Issue1355(TestDevice testDevice) : base(testDevice) public Issue1355(TestDevice testDevice) : base(testDevice)
{ {
@ -18,11 +16,9 @@ public class Issue1355 : _IssuesUITest
[Test] [Test]
[Category(UITestCategories.LifeCycle)] [Category(UITestCategories.LifeCycle)]
[Category(UITestCategories.Compatibility)] [Category(UITestCategories.Compatibility)]
[FailsOnAndroidWhenRunningOnXamarinUITest]
public void SwitchMainPageOnAppearing() public void SwitchMainPageOnAppearing()
{ {
// Without the fix, this would crash. If we're here at all, the test passed. // Without the fix, this would crash. If we're here at all, the test passed.
App.WaitForNoElement(Success); App.WaitForElement("Success");
} }
} }
#endif

Просмотреть файл

@ -1,22 +0,0 @@
using NUnit.Framework;
using UITest.Appium;
using UITest.Core;
namespace Microsoft.Maui.TestCases.Tests.Issues;
public class GitHub1355_Forms : _IssuesUITest
{
public GitHub1355_Forms(TestDevice testDevice) : base(testDevice)
{
}
public override string Issue => "[Android] ViewCell shows ContextActions on tap instead of long press";
// [Test]
// [Category(UITestCategories.Navigation)]
// public void SwitchMainPageOnAppearing()
// {
// // Without the fix, this would crash. If we're here at all, the test passed.
// App.WaitForElement(Success);
// }
}

Просмотреть файл

@ -6,20 +6,24 @@ namespace Microsoft.Maui.TestCases.Tests.Issues;
public class Issue2740 : _IssuesUITest public class Issue2740 : _IssuesUITest
{ {
const string Switch = "Switch";
const string ListItem = "1";
public Issue2740(TestDevice testDevice) : base(testDevice) public Issue2740(TestDevice testDevice) : base(testDevice)
{ {
} }
public override string Issue => "System.NotSupportedException: Unable to activate instance of type Microsoft.Maui.Controls.Platform.Android.PageContainer from native handle"; public override string Issue => "System.NotSupportedException: Unable to activate instance of type Microsoft.Maui.Controls.Platform.Android.PageContainer from native handle";
// [Test] [Test]
// [Category(UITestCategories.LifeCycle)] [Category(UITestCategories.LifeCycle)]
// public void Issue2740Test() public void Issue2740Test()
// { {
// App.WaitForElement(q => q.Marked("1")); App.WaitForElement(ListItem);
// App.Tap(q => q.Marked("1")); App.Tap(ListItem);
// App.WaitForElement(q => q.Marked("Switch")); App.WaitForElement(Switch);
// App.Tap(q => q.Marked("Switch")); App.Tap(Switch);
// App.WaitForElement(q => q.Marked("1")); App.WaitForElement(ListItem);
// } }
} }

Просмотреть файл

@ -13,18 +13,11 @@ public class Issue2923 : _IssuesUITest
public override string Issue => "First tab does not load until navigating"; public override string Issue => "First tab does not load until navigating";
// [Test] [Test]
// public void Issue2923TestOne() public void Issue2923TestOne()
// { {
// App.WaitForElement(q => q.Marked("FirstPageLabel")); App.WaitForElement("FirstPageLabel");
// App.Screenshot("First Tab is showing"); App.Tap("ResetButton");
// } App.WaitForElement("ResetPageLabel");
}
// [Test]
// public void Issue2923TestTwo()
// {
// App.Tap(q => q.Marked("ResetButton"));
// App.Screenshot("Tabs Reset");
// App.WaitForElement(q => q.Marked("ResetPageLabel"));
// }
} }

Просмотреть файл

@ -12,13 +12,12 @@ public class ListViewNRE : _IssuesUITest
public override string Issue => "ListView crashes when disposed on ItemSelected"; public override string Issue => "ListView crashes when disposed on ItemSelected";
//[Test] [Test]
//[Category(UITestCategories.ListView)] [Category(UITestCategories.ListView)]
//[FailsOnIOS] public void ListViewNRETest()
//public void ListViewNRETest() {
//{ App.WaitForElement("1");
// App.WaitForElement(q => q.Marked("1")); App.Tap("1");
// App.Tap(q => q.Marked("1")); App.WaitForElement("Success");
// App.WaitForElement(q => q.Marked(Success)); }
//}
} }