From ba3aec28ad5f3ab31fd4a6627f1ee964f31451e0 Mon Sep 17 00:00:00 2001 From: Anandhan Rajagopal <97146406+anandhan-rajagopal@users.noreply.github.com> Date: Wed, 11 Dec 2024 01:13:54 +0530 Subject: [PATCH] [Testing] Enabling ported UITests from Xamarin.UITests to Appium - 36 (#26436) * Enabled 36th set of Migrated UITests from XamarinUITest to Appium (#35) * Migrated Issues for Issue8964 , Issue7329, Issue6932_emptyviewstring, Issue6932_emptyviewstring * Updated modified tests * Modified the enabled tests * Updated 6932 * Removed unwanted spaces --------- Co-authored-by: HarishKumarSF4517 * Resolved CI failure on iOS --------- Co-authored-by: HarishKumarSF4517 --- .../XFIssue/Issue6932_emptyviewstring.cs | 81 ++++++++----------- .../XFIssue/Issue6932_emptyviewtemplate.cs | 78 ++++++++---------- .../Tests/Issues/XFIssue/Issue7329.cs | 53 +++++------- .../Tests/Issues/XFIssue/Issue8964.cs | 63 +++++++-------- 4 files changed, 121 insertions(+), 154 deletions(-) diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewstring.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewstring.cs index 39c68b6eddf7..ebcc1443919d 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewstring.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewstring.cs @@ -7,56 +7,45 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; [Category(UITestCategories.Layout)] public class Issue6932_emptyviewstring : _IssuesUITest { + const int Count = 10; + const string LayoutAutomationId = "1"; + const string AddAutomationId = "Add"; + const string RemoveAutomationId = "Remove"; + const string ClearAutomationId = "Clear"; + const string EmptyViewStringDescription = "Nothing to see here"; + public Issue6932_emptyviewstring(TestDevice testDevice) : base(testDevice) { } public override string Issue => "EmptyView for BindableLayout (string)"; + + [Test] + public void BEmptyViewStringBecomesVisibleWhenItemsSourceIsCleared() + { + App.WaitForElement(AddAutomationId); + for (var i = 0; i < Count/2; i++) + App.Tap(AddAutomationId); + App.Tap(ClearAutomationId); + App.WaitForElement(EmptyViewStringDescription); + } + + [Test] + public void AEmptyViewStringBecomesVisibleWhenItemsSourceIsEmptiedOneByOne() + { + App.WaitForElement(LayoutAutomationId); - //[Test] - //[FailsOnMauiIOS] - //public void EmptyViewStringBecomesVisibleWhenItemsSourceIsCleared() - //{ - // App.Screenshot("Screen opens, items are shown"); - - // App.WaitForElement(_viewModel.LayoutAutomationId); - // App.Tap(_viewModel.ClearAutomationId); - // App.WaitForElement(_viewModel.EmptyViewStringDescription); - - // App.Screenshot("Empty view is visible"); - //} - - //[Test] - //[FailsOnMauiIOS] - //public void EmptyViewStringBecomesVisibleWhenItemsSourceIsEmptiedOneByOne() - //{ - // App.Screenshot("Screen opens, items are shown"); - - // App.WaitForElement(_viewModel.LayoutAutomationId); - - // for (var i = 0; i < _viewModel.ItemsSource.Count; i++) - // App.Tap(_viewModel.RemoveAutomationId); - - // App.WaitForElement(_viewModel.EmptyViewStringDescription); - - // App.Screenshot("Empty view is visible"); - //} - - //[Test] - //[FailsOnMauiIOS] - //public void EmptyViewStringHidesWhenItemsSourceIsFilled() - //{ - // App.Screenshot("Screen opens, items are shown"); - - // App.WaitForElement(_viewModel.LayoutAutomationId); - // App.Tap(_viewModel.ClearAutomationId); - // App.WaitForElement(_viewModel.EmptyViewStringDescription); - - // App.Screenshot("Items are cleared, empty view visible"); - - // App.Tap(_viewModel.AddAutomationId); - // App.WaitForNoElement(_viewModel.EmptyViewStringDescription); - - // App.Screenshot("Item is added, empty view is not visible"); - //} + for (var i = 0; i < Count; i++) + App.Tap(RemoveAutomationId); + + App.WaitForElement(EmptyViewStringDescription); + } + + [Test] + public void CEmptyViewStringHidesWhenItemsSourceIsFilled() + { + App.WaitForElement(EmptyViewStringDescription); + App.Tap(AddAutomationId); + App.WaitForNoElement(EmptyViewStringDescription); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewtemplate.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewtemplate.cs index e2a0d4b4873e..120cb947fd93 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewtemplate.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue6932_emptyviewtemplate.cs @@ -7,56 +7,46 @@ namespace Microsoft.Maui.TestCases.Tests.Issues; [Category(UITestCategories.Layout)] public class Issue6932_emptyviewtemplate : _IssuesUITest { + const int Count = 10; + const string LayoutAutomationId = "1"; + const string AddAutomationId = "Add"; + const string RemoveAutomationId = "Remove"; + const string ClearAutomationId = "Clear"; + const string EmptyTemplateAutomationId = "No items here"; public Issue6932_emptyviewtemplate(TestDevice testDevice) : base(testDevice) { } public override string Issue => "EmptyView for BindableLayout (template)"; - //[Test] - //[FailsOnMauiIOS] - //public void EmptyViewTemplateBecomesVisibleWhenItemsSourceIsCleared() - //{ - // App.Screenshot("Screen opens, items are shown"); - - // App.WaitForElement(_viewModel.LayoutAutomationId); - // App.Tap(_viewModel.ClearAutomationId); - // App.WaitForElement(_viewModel.EmptyTemplateAutomationId); - - // App.Screenshot("Empty view is visible"); - //} - - //[Test] - //[FailsOnMauiIOS] - //public void EmptyViewTemplateBecomesVisibleWhenItemsSourceIsEmptiedOneByOne() - //{ - // App.Screenshot("Screen opens, items are shown"); - - // App.WaitForElement(_viewModel.LayoutAutomationId); - - // for (var i = 0; i < _viewModel.ItemsSource.Count; i++) - // App.Tap(_viewModel.RemoveAutomationId); - - // App.WaitForElement(_viewModel.EmptyTemplateAutomationId); - - // App.Screenshot("Empty view is visible"); - //} - - //[Test] - //[FailsOnMauiIOS] - //public void EmptyViewTemplateHidesWhenItemsSourceIsFilled() - //{ - // App.Screenshot("Screen opens, items are shown"); - - // App.WaitForElement(_viewModel.LayoutAutomationId); - // App.Tap(_viewModel.ClearAutomationId); - // App.WaitForElement(_viewModel.EmptyTemplateAutomationId); - - // App.Screenshot("Items are cleared, empty view visible"); + [Test] + public void BEmptyViewTemplateBecomesVisibleWhenItemsSourceIsCleared() + { + App.WaitForElement(AddAutomationId); - // App.Tap(_viewModel.AddAutomationId); - // App.WaitForNoElement(_viewModel.EmptyTemplateAutomationId); + for (var i = 0; i < Count / 2; i++) + App.Tap(AddAutomationId); - // App.Screenshot("Item is added, empty view is not visible"); - //} + App.Tap(ClearAutomationId); + App.WaitForElement(EmptyTemplateAutomationId); + } + + [Test] + public void AEmptyViewTemplateBecomesVisibleWhenItemsSourceIsEmptiedOneByOne() + { + App.WaitForElement(LayoutAutomationId); + + for (var i = 0; i < Count; i++) + App.Tap(RemoveAutomationId); + + App.WaitForElement(EmptyTemplateAutomationId); + } + + [Test] + public void CEmptyViewTemplateHidesWhenItemsSourceIsFilled() + { + App.WaitForElement(EmptyTemplateAutomationId); + App.Tap(AddAutomationId); + App.WaitForNoElement(EmptyTemplateAutomationId); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue7329.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue7329.cs index 9114b92d8afd..e590095f4441 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue7329.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue7329.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_CATALYST //In Catalyst, `ScrollDown` isn't functioning correctly with Appium. +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,34 +13,22 @@ public Issue7329(TestDevice testDevice) : base(testDevice) public override string Issue => "[Android] ListView scroll not working when inside a ScrollView"; - //[Test] - //[Category(UITestCategories.ScrollView)] - - //[FailsOnAndroid] - //[FailsOnIOS] - //public void ScrollListViewInsideScrollView() - //{ - // if (!OperatingSystem.IsAndroidVersionAtLeast(21)) - // { - // return; - // } - - // App.WaitForElement("1"); - - // App.QueryUntilPresent(() => - // { - // try - // { - // App.ScrollDownTo("30", strategy: ScrollStrategy.Gesture, swipeSpeed: 100); - // } - // catch - // { - // // just ignore if it fails so it can keep trying to scroll - // } - - // return App.Query("30"); - // }); - - // App.Query("30"); - //} -} \ No newline at end of file + [Test] + [Category(UITestCategories.ScrollView)] + public void ScrollListViewInsideScrollView() + { + App.WaitForElement("1"); + + App.ScrollDown("NestedListView"); + +#if IOS + // In iOS, WaitForNoElement throws a timeout exception eventhough the text is not visible on the screen. So using the ListView Items to ensure scroll. + App.WaitForElement("80"); +#else + // App.QueryUntilPresent isn't functioning correctly; it throws a timeout exception immediately after the first try. + // Verifying that instructions label is not visible also confirms that the ListView has scrolled. + App.WaitForNoElement("If the List View can scroll the test has passed"); +#endif + } +} +#endif \ No newline at end of file diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8964.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8964.cs index 91e1d07cf015..6d77bb7dcb8e 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8964.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/Issues/XFIssue/Issue8964.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +#if TEST_FAILS_ON_CATALYST && TEST_FAILS_ON_WINDOWS && TEST_FAILS_ON_ANDROID //The Position property now functions correctly on Android and Windows, issue: https://github.com/dotnet/maui/issues/15443. Note that on Catalyst, swipe and drag options are not supported in Appium. +using NUnit.Framework; using UITest.Appium; using UITest.Core; @@ -12,34 +13,32 @@ public Issue8964(TestDevice testDevice) : base(testDevice) public override string Issue => "Adding an item to the beginning of the bound ItemSource causes the carousel to skip sometimes"; - //[Test] - //[Category(UITestCategories.CarouselView)] - // [FailsOnAndroid] - // [FailsOnIOS] - // public void Issue8964Test() - // { - // App.WaitForElement(q => q.Marked($"Item Position - 4")); - // var rect = App.Query("carouseView")[0].Rect; - // SwipePreviousItem(rect); - // App.WaitForElement(q => q.Marked($"Item Position - 4")); - // SwipePreviousItem(rect); - // App.WaitForElement(q => q.Marked($"Item Position - 4")); - // SwipePreviousItem(rect); - // App.WaitForElement(q => q.Marked($"Item Position - 4")); - // SwipePreviousItem(rect); - // App.WaitForElement(q => q.Marked($"Item Position - 4")); - // SwipePreviousItem(rect); - // App.WaitForElement(q => q.Marked($"Item Position - 4")); - // App.WaitForElement(q => q.Marked($"Counter 6")); - - // } - - // void SwipePreviousItem(Xamarin.UITest.Queries.AppRect rect) - // { - //#if ANDROID - // App.DragCoordinates(rect.X + 10, rect.Y, rect.X + rect.Width - 10, rect.Y); - //#else - // App.SwipeLeftToRight("carouseView"); - //#endif - // } -} \ No newline at end of file + [Test] + [Category(UITestCategories.CarouselView)] + public void Issue8964Test() + { + App.WaitForElement($"Item Position - 4"); + var rect = App.WaitForElement("carouseView").GetRect(); + SwipePreviousItem(rect); + App.WaitForElement($"Item Position - 4"); + SwipePreviousItem(rect); + App.WaitForElement($"Item Position - 4"); + SwipePreviousItem(rect); + App.WaitForElement($"Item Position - 4"); + SwipePreviousItem(rect); + App.WaitForElement($"Item Position - 4"); + SwipePreviousItem(rect); + App.WaitForElement( $"Item Position - 4"); + App.WaitForElement($"Counter 6"); + } + + void SwipePreviousItem(System.Drawing.Rectangle rect) + { +#if ANDROID + App.DragCoordinates(rect.X + 10, rect.Y, rect.X + rect.Width - 10, rect.Y); +#else + App.SwipeLeftToRight("carouseView"); +#endif + } +} +#endif \ No newline at end of file