From a46dcefc3c5690a0bd3c540a8a8ff131ef1ffd2f Mon Sep 17 00:00:00 2001 From: Shane Neuville Date: Fri, 9 Aug 2019 11:56:00 -0600 Subject: [PATCH] [UITest] Fix 2951 and moved extension method to be more visible (#7108) * [UITest] Fix 2951 and moved extension method to be more visible * fix spacing * tabs --- .../Bugzilla26993.cs | 45 ++++---- .../Github5623.xaml.cs | 14 +-- .../Issue2951.xaml.cs | 119 ++++++++++++++------- .../Issue4597.cs | 12 +-- .../Issue4915.xaml.cs | 2 +- .../Issue6286.cs | 4 +- .../Utilities/AppExtensions.cs | 10 +- 7 files changed, 126 insertions(+), 80 deletions(-) diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla26993.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla26993.cs index b64ce6f..c600ed6 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla26993.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla26993.cs @@ -14,28 +14,30 @@ namespace Xamarin.Forms.Controls.Issues #if UITEST [NUnit.Framework.Category(Core.UITests.UITestCategories.UwpIgnore)] #endif - [Preserve (AllMembers = true)] - [Issue (IssueTracker.Bugzilla, 26993, "https://bugzilla.xamarin.com/show_bug.cgi?id=26993")] + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 26993, "https://bugzilla.xamarin.com/show_bug.cgi?id=26993")] public class Bugzilla26993 : TestContentPage // or TestMasterDetailPage, etc ... { - [Preserve (AllMembers = true)] - public class Bz26993ViewCell : ViewCell + [Preserve(AllMembers = true)] + public class Bz26993ViewCell : ViewCell { public static int s_id = 0; - public Bz26993ViewCell () + public Bz26993ViewCell() { - View = new WebView { + View = new WebView + { AutomationId = "AutomationId" + s_id, HeightRequest = 300, - Source = new HtmlWebViewSource { + Source = new HtmlWebViewSource + { Html = "

Xamarin.Forms " + s_id + "

The CSS and image are loaded from local files!

next page

" } }; } } - protected override void Init () + protected override void Init() { Bz26993ViewCell.s_id = 0; @@ -77,9 +79,10 @@ namespace Xamarin.Forms.Controls.Issues "", "", }; - - Content = new StackLayout { - Children = { + + Content = new StackLayout + { + Children = { new ListView { RowHeight = 300, ItemsSource = itemSource, @@ -94,22 +97,22 @@ namespace Xamarin.Forms.Controls.Issues #if __MACOS__ [Ignore("Webview query is not implemented yet on UITEst desktop")] #endif - public void Bugzilla26993Test () + public void Bugzilla26993Test() { - RunningApp.Screenshot ("I am at BZ26993"); + RunningApp.Screenshot("I am at BZ26993"); - RunningApp.WaitForElement (q=>q.WebView(0).Css("#CellID0")); - RunningApp.Tap (q=>q.WebView(0).Css("#LinkID0")); + RunningApp.WaitForElement(q => q.WebView(0).Css("#CellID0")); + RunningApp.Tap(q => q.WebView(0).Css("#LinkID0")); - RunningApp.Screenshot ("Load local HTML"); + RunningApp.Screenshot("Load local HTML"); - RunningApp.WaitForNoElement (q=>q.WebView(0).Css("#LinkID0")); - UITest.Queries.AppWebResult[] newElem = - RunningApp.RetryUntilPresent(()=> RunningApp.Query (q => q.WebView (0).Css ("h1"))); + RunningApp.WaitForNoElement(q => q.WebView(0).Css("#LinkID0")); + UITest.Queries.AppWebResult[] newElem = + RunningApp.QueryUntilPresent(() => RunningApp.Query(q => q.WebView(0).Css("h1"))); - Assert.AreEqual ("#LocalHtmlPage", newElem[0].Id); + Assert.AreEqual("#LocalHtmlPage", newElem[0].Id); - RunningApp.Screenshot ("I see the Label"); + RunningApp.Screenshot("I see the Label"); } #endif } diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github5623.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github5623.xaml.cs index e810fd2..dc5d04e 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github5623.xaml.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Github5623.xaml.cs @@ -117,20 +117,20 @@ namespace Xamarin.Forms.Controls.Issues [Test] public void CollectionViewInfiniteScroll() { - RunningApp.WaitForElement ("CollectionView5623"); + RunningApp.WaitForElement("CollectionView5623"); var colView = RunningApp.Query("CollectionView5623").Single(); AppResult[] lastCellResults = null; - RunningApp.RetryUntilPresent(() => - { - RunningApp.DragCoordinates(colView.Rect.CenterX, colView.Rect.Y + colView.Rect.Height - 50, colView.Rect.CenterX, colView.Rect.Y + 5); + RunningApp.QueryUntilPresent(() => + { + RunningApp.DragCoordinates(colView.Rect.CenterX, colView.Rect.Y + colView.Rect.Height - 50, colView.Rect.CenterX, colView.Rect.Y + 5); - lastCellResults = RunningApp.Query("99"); + lastCellResults = RunningApp.Query("99"); - return lastCellResults; - }, 100, 1); + return lastCellResults; + }, 100, 1); Assert.IsTrue(lastCellResults?.Any() ?? false); } diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2951.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2951.xaml.cs index 459fe85..f2931fb 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2951.xaml.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue2951.xaml.cs @@ -9,7 +9,9 @@ using System.Threading.Tasks; #if UITEST using Xamarin.UITest.Queries; +using Xamarin.UITest; using NUnit.Framework; +using Xamarin.Forms.Core.UITests; #endif @@ -18,11 +20,11 @@ namespace Xamarin.Forms.Controls.Issues #if UITEST [NUnit.Framework.Category(Core.UITests.UITestCategories.UwpIgnore)] #endif - [Preserve (AllMembers = true)] - [Issue (IssueTracker.Github, 2951, "On Android, button background is not updated when color changes ")] + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Github, 2951, "On Android, button background is not updated when color changes ")] public partial class Issue2951 : TestContentPage { - public Issue2951 () + public Issue2951() { #if APP InitializeComponent (); @@ -31,7 +33,7 @@ namespace Xamarin.Forms.Controls.Issues async void ListView_ItemAppearing(object sender, ItemVisibilityEventArgs e) { - if(e.ItemIndex == 2) + if (e.ItemIndex == 2) { await Task.Delay(10); #if APP @@ -40,93 +42,128 @@ namespace Xamarin.Forms.Controls.Issues } } - protected override void Init () + protected override void Init() { - BindingContext = new MyViewModel (); + BindingContext = new MyViewModel(); } - [Preserve (AllMembers = true)] + [Preserve(AllMembers = true)] public class MyViewModel { public ObservableCollection Items { get; private set; } public Command ButtonTapped { get; private set; } - public MyViewModel () + public MyViewModel() { - ButtonTapped = new Command (OnItemTapped); + ButtonTapped = new Command(OnItemTapped); - Items = new ObservableCollection (); + Items = new ObservableCollection(); - Items.Add (new MyItemViewModel { Name = "A", IsStarted = false }); - Items.Add (new MyItemViewModel { Name = "B", IsStarted = false }); - Items.Add (new MyItemViewModel { Name = "C", IsStarted = false }); + Items.Add(new MyItemViewModel { Name = "A", IsStarted = false }); + Items.Add(new MyItemViewModel { Name = "B", IsStarted = false }); + Items.Add(new MyItemViewModel { Name = "C", IsStarted = false }); } - void OnItemTapped (MyItemViewModel model) + void OnItemTapped(MyItemViewModel model) { - if (model.IsStarted) { - Items.Remove (model); - } else { + if (model.IsStarted) + { + Items.Remove(model); + } + else + { model.IsStarted = true; } } } - [Preserve (AllMembers = true)] + [Preserve(AllMembers = true)] public class MyItemViewModel : INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; string _name; - public string Name { - get { return _name; } - set { + public string Name + { + get { return _name; } + set + { _name = value; - OnPropertyChanged ("Name"); + OnPropertyChanged("Name"); } } bool _isStarted; - public bool IsStarted { - get { return _isStarted; } - set { + public bool IsStarted + { + get { return _isStarted; } + set + { _isStarted = value; - OnPropertyChanged ("IsStarted"); + OnPropertyChanged("IsStarted"); } } - void OnPropertyChanged (string propertyName) + void OnPropertyChanged(string propertyName) { - if (PropertyChanged != null) { - PropertyChanged (this, new PropertyChangedEventArgs (propertyName)); + if (PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } } #if UITEST [Test] - public void Issue2951Test () + public void Issue2951Test() { RunningApp.WaitForElement("Ready"); - var bt = RunningApp.WaitForElement (c => c.Marked ("btnChangeStatus")); - var buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus")); - Assert.That (buttons.Length, Is.EqualTo (3)); - RunningApp.Tap(c => c.Marked ("btnChangeStatus").Index(1)); - buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus")); - var text = buttons [1].Text ?? buttons [1].Label; - Assert.That (text, Is.EqualTo ("B")); - RunningApp.Tap(c => c.Marked ("btnChangeStatus").Index(1)); - buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus")); - Assert.That (buttons.Length, Is.EqualTo (2)); + var bt = RunningApp.WaitForElement(c => c.Marked("btnChangeStatus")); + + var buttons = RunningApp.QueryUntilPresent(() => + { + var results = RunningApp.Query("btnChangeStatus"); + if (results.Length == 3) + return results; + + return null; + }); + + Assert.That(buttons.Length, Is.EqualTo(3)); + RunningApp.Tap(c => c.Marked("btnChangeStatus").Index(1)); + + buttons = RunningApp.QueryUntilPresent(() => + { + var results = RunningApp.Query("btnChangeStatus"); + if ((results[1].Text ?? results[1].Label) == "B") + return results; + + return null; + }); + + var text = buttons[1].Text ?? buttons[1].Label; + Assert.That(text, Is.EqualTo("B")); + RunningApp.Tap(c => c.Marked("btnChangeStatus").Index(1)); + + buttons = RunningApp.QueryUntilPresent(() => + { + var results = RunningApp.Query("btnChangeStatus"); + if (results.Length == 2) + return results; + + return null; + }); + + Assert.That(buttons.Length, Is.EqualTo(2)); //TODO: we should check the color of the button //var buttonTextColor = GetProperty ("btnChangeStatus", Button.BackgroundColorProperty); //Assert.AreEqual (Color.Pink, buttonTextColor); } - + #endif } } diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4597.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4597.cs index a3049eb..81bb2af 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4597.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4597.cs @@ -119,7 +119,7 @@ namespace Xamarin.Forms.Controls.Issues }; - foreach(var view in imageControls) + foreach (var view in imageControls) { view.BackgroundColor = Color.Red; } @@ -129,7 +129,7 @@ namespace Xamarin.Forms.Controls.Issues { AutomationId = "layoutContainer", Children = - { + { new StackLayout() { Orientation = StackOrientation.Horizontal, @@ -137,7 +137,7 @@ namespace Xamarin.Forms.Controls.Issues { labelActiveTest, switchToUri, - sourceLabel + sourceLabel } }, button, @@ -228,7 +228,7 @@ namespace Xamarin.Forms.Controls.Issues SetupTest(nameof(ListView), fileSource); var imageVisible = - RunningApp.RetryUntilPresent(GetImage, 10, 2000); + RunningApp.QueryUntilPresent(GetImage, 10, 2000); Assert.AreEqual(1, imageVisible.Length); SetImageSourceToNull(); @@ -261,7 +261,7 @@ namespace Xamarin.Forms.Controls.Issues UITest.Queries.AppResult TestForImageVisible() { - var images = RunningApp.RetryUntilPresent(() => + var images = RunningApp.QueryUntilPresent(() => { var result = RunningApp.WaitForElement(_fileNameAutomationId); @@ -273,7 +273,7 @@ namespace Xamarin.Forms.Controls.Issues Assert.AreEqual(1, images.Length); var imageVisible = images[0]; - + Assert.Greater(imageVisible.Rect.Height, 1); Assert.Greater(imageVisible.Rect.Width, 1); return imageVisible; diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4915.xaml.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4915.xaml.cs index 22b06f1..f8c40a2 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4915.xaml.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue4915.xaml.cs @@ -52,7 +52,7 @@ namespace Xamarin.Forms.Controls.Issues public void LegacyImageSourceProperties() { RunningApp.WaitForElement("Nothing Crashed"); - RunningApp.RetryUntilPresent( + RunningApp.QueryUntilPresent( () => { var result = RunningApp.WaitForElement("Image1"); diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6286.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6286.cs index 789d077..06e5448 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6286.cs +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Issue6286.cs @@ -58,7 +58,7 @@ namespace Xamarin.Forms.Controls.Issues page1.Content = new Label { Text = "success", AutomationId = "success" }; } - catch(Exception exc) + catch (Exception exc) { page1.Content = new Label { Text = $"{exc}", AutomationId = "failure" }; } @@ -75,7 +75,7 @@ namespace Xamarin.Forms.Controls.Issues [Test] public void Issue6286_WebView_Test() { - RunningApp.RetryUntilPresent(() => RunningApp.WaitForElement("success")); + RunningApp.QueryUntilPresent(() => RunningApp.WaitForElement("success")); } #endif } diff --git a/Xamarin.Forms.Core.UITests.Shared/Utilities/AppExtensions.cs b/Xamarin.Forms.Core.UITests.Shared/Utilities/AppExtensions.cs index 061caa4..1808c3a 100644 --- a/Xamarin.Forms.Core.UITests.Shared/Utilities/AppExtensions.cs +++ b/Xamarin.Forms.Core.UITests.Shared/Utilities/AppExtensions.cs @@ -6,11 +6,11 @@ using Xamarin.UITest.Queries; using System.Text.RegularExpressions; using System.Threading; -namespace Xamarin.Forms.Core.UITests +namespace Xamarin.UITest { internal static class AppExtensions { - public static T[] RetryUntilPresent( + public static T[] QueryUntilPresent( this IApp app, Func func, int retryCount = 10, @@ -28,7 +28,13 @@ namespace Xamarin.Forms.Core.UITests return results; } + } +} +namespace Xamarin.Forms.Core.UITests +{ + internal static class AppExtensions + { public static AppRect ScreenBounds(this IApp app) { return app.Query(Queries.Root()).First().Rect; -- 2.7.4