[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
This commit is contained in:
Shane Neuville 2019-08-09 11:56:00 -06:00 коммит произвёл Rui Marinho
Родитель d75fa4fa92
Коммит a46dcefc3c
7 изменённых файлов: 126 добавлений и 80 удалений

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

@ -14,28 +14,30 @@ namespace Xamarin.Forms.Controls.Issues
#if UITEST #if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.UwpIgnore)] [NUnit.Framework.Category(Core.UITests.UITestCategories.UwpIgnore)]
#endif #endif
[Preserve (AllMembers = true)] [Preserve(AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 26993, "https://bugzilla.xamarin.com/show_bug.cgi?id=26993")] [Issue(IssueTracker.Bugzilla, 26993, "https://bugzilla.xamarin.com/show_bug.cgi?id=26993")]
public class Bugzilla26993 : TestContentPage // or TestMasterDetailPage, etc ... public class Bugzilla26993 : TestContentPage // or TestMasterDetailPage, etc ...
{ {
[Preserve (AllMembers = true)] [Preserve(AllMembers = true)]
public class Bz26993ViewCell : ViewCell public class Bz26993ViewCell : ViewCell
{ {
public static int s_id = 0; public static int s_id = 0;
public Bz26993ViewCell () public Bz26993ViewCell()
{
View = new WebView
{ {
View = new WebView {
AutomationId = "AutomationId" + s_id, AutomationId = "AutomationId" + s_id,
HeightRequest = 300, HeightRequest = 300,
Source = new HtmlWebViewSource { Source = new HtmlWebViewSource
{
Html = "<html><head><link rel=\"stylesheet\" href=\"default.css\"></head><body><h1 id=\"CellID" + s_id + "\">Xamarin.Forms " + s_id + "</h1><p>The CSS and image are loaded from local files!</p><img src='WebImages/XamarinLogo.png'/><p><a id=\"LinkID" + s_id++ + "\" href=\"local.html\">next page</a></p></body></html>" Html = "<html><head><link rel=\"stylesheet\" href=\"default.css\"></head><body><h1 id=\"CellID" + s_id + "\">Xamarin.Forms " + s_id + "</h1><p>The CSS and image are loaded from local files!</p><img src='WebImages/XamarinLogo.png'/><p><a id=\"LinkID" + s_id++ + "\" href=\"local.html\">next page</a></p></body></html>"
} }
}; };
} }
} }
protected override void Init () protected override void Init()
{ {
Bz26993ViewCell.s_id = 0; Bz26993ViewCell.s_id = 0;
@ -78,7 +80,8 @@ namespace Xamarin.Forms.Controls.Issues
"", "",
}; };
Content = new StackLayout { Content = new StackLayout
{
Children = { Children = {
new ListView { new ListView {
RowHeight = 300, RowHeight = 300,
@ -94,22 +97,22 @@ namespace Xamarin.Forms.Controls.Issues
#if __MACOS__ #if __MACOS__
[Ignore("Webview query is not implemented yet on UITEst desktop")] [Ignore("Webview query is not implemented yet on UITEst desktop")]
#endif #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.WaitForElement(q => q.WebView(0).Css("#CellID0"));
RunningApp.Tap (q=>q.WebView(0).Css("#LinkID0")); 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")); RunningApp.WaitForNoElement(q => q.WebView(0).Css("#LinkID0"));
UITest.Queries.AppWebResult[] newElem = UITest.Queries.AppWebResult[] newElem =
RunningApp.RetryUntilPresent(()=> RunningApp.Query (q => q.WebView (0).Css ("h1"))); 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 #endif
} }

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

@ -117,13 +117,13 @@ namespace Xamarin.Forms.Controls.Issues
[Test] [Test]
public void CollectionViewInfiniteScroll() public void CollectionViewInfiniteScroll()
{ {
RunningApp.WaitForElement ("CollectionView5623"); RunningApp.WaitForElement("CollectionView5623");
var colView = RunningApp.Query("CollectionView5623").Single(); var colView = RunningApp.Query("CollectionView5623").Single();
AppResult[] lastCellResults = null; AppResult[] lastCellResults = null;
RunningApp.RetryUntilPresent(() => RunningApp.QueryUntilPresent(() =>
{ {
RunningApp.DragCoordinates(colView.Rect.CenterX, colView.Rect.Y + colView.Rect.Height - 50, colView.Rect.CenterX, colView.Rect.Y + 5); RunningApp.DragCoordinates(colView.Rect.CenterX, colView.Rect.Y + colView.Rect.Height - 50, colView.Rect.CenterX, colView.Rect.Y + 5);

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

@ -9,7 +9,9 @@ using System.Threading.Tasks;
#if UITEST #if UITEST
using Xamarin.UITest.Queries; using Xamarin.UITest.Queries;
using Xamarin.UITest;
using NUnit.Framework; using NUnit.Framework;
using Xamarin.Forms.Core.UITests;
#endif #endif
@ -18,11 +20,11 @@ namespace Xamarin.Forms.Controls.Issues
#if UITEST #if UITEST
[NUnit.Framework.Category(Core.UITests.UITestCategories.UwpIgnore)] [NUnit.Framework.Category(Core.UITests.UITestCategories.UwpIgnore)]
#endif #endif
[Preserve (AllMembers = true)] [Preserve(AllMembers = true)]
[Issue (IssueTracker.Github, 2951, "On Android, button background is not updated when color changes ")] [Issue(IssueTracker.Github, 2951, "On Android, button background is not updated when color changes ")]
public partial class Issue2951 : TestContentPage public partial class Issue2951 : TestContentPage
{ {
public Issue2951 () public Issue2951()
{ {
#if APP #if APP
InitializeComponent (); InitializeComponent ();
@ -31,7 +33,7 @@ namespace Xamarin.Forms.Controls.Issues
async void ListView_ItemAppearing(object sender, ItemVisibilityEventArgs e) async void ListView_ItemAppearing(object sender, ItemVisibilityEventArgs e)
{ {
if(e.ItemIndex == 2) if (e.ItemIndex == 2)
{ {
await Task.Delay(10); await Task.Delay(10);
#if APP #if APP
@ -40,87 +42,122 @@ 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 class MyViewModel
{ {
public ObservableCollection<MyItemViewModel> Items { get; private set; } public ObservableCollection<MyItemViewModel> Items { get; private set; }
public Command<MyItemViewModel> ButtonTapped { get; private set; } public Command<MyItemViewModel> ButtonTapped { get; private set; }
public MyViewModel () public MyViewModel()
{ {
ButtonTapped = new Command<MyItemViewModel> (OnItemTapped); ButtonTapped = new Command<MyItemViewModel>(OnItemTapped);
Items = new ObservableCollection<MyItemViewModel> (); Items = new ObservableCollection<MyItemViewModel>();
Items.Add (new MyItemViewModel { Name = "A", IsStarted = false }); Items.Add(new MyItemViewModel { Name = "A", IsStarted = false });
Items.Add (new MyItemViewModel { Name = "B", IsStarted = false }); Items.Add(new MyItemViewModel { Name = "B", IsStarted = false });
Items.Add (new MyItemViewModel { Name = "C", 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; model.IsStarted = true;
} }
} }
} }
[Preserve (AllMembers = true)] [Preserve(AllMembers = true)]
public class MyItemViewModel : INotifyPropertyChanged public class MyItemViewModel : INotifyPropertyChanged
{ {
public event PropertyChangedEventHandler PropertyChanged; public event PropertyChangedEventHandler PropertyChanged;
string _name; string _name;
public string Name { public string Name
{
get { return _name; } get { return _name; }
set { set
{
_name = value; _name = value;
OnPropertyChanged ("Name"); OnPropertyChanged("Name");
} }
} }
bool _isStarted; bool _isStarted;
public bool IsStarted { public bool IsStarted
{
get { return _isStarted; } get { return _isStarted; }
set { set
{
_isStarted = value; _isStarted = value;
OnPropertyChanged ("IsStarted"); OnPropertyChanged("IsStarted");
} }
} }
void OnPropertyChanged (string propertyName) void OnPropertyChanged(string propertyName)
{ {
if (PropertyChanged != null) { if (PropertyChanged != null)
PropertyChanged (this, new PropertyChangedEventArgs (propertyName)); {
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
} }
} }
} }
#if UITEST #if UITEST
[Test] [Test]
public void Issue2951Test () public void Issue2951Test()
{ {
RunningApp.WaitForElement("Ready"); RunningApp.WaitForElement("Ready");
var bt = RunningApp.WaitForElement (c => c.Marked ("btnChangeStatus")); var bt = RunningApp.WaitForElement(c => c.Marked("btnChangeStatus"));
var buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus"));
Assert.That (buttons.Length, Is.EqualTo (3)); var buttons = RunningApp.QueryUntilPresent(() =>
RunningApp.Tap(c => c.Marked ("btnChangeStatus").Index(1)); {
buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus")); var results = RunningApp.Query("btnChangeStatus");
var text = buttons [1].Text ?? buttons [1].Label; if (results.Length == 3)
Assert.That (text, Is.EqualTo ("B")); return results;
RunningApp.Tap(c => c.Marked ("btnChangeStatus").Index(1));
buttons = RunningApp.Query (c => c.Marked ("btnChangeStatus")); return null;
Assert.That (buttons.Length, Is.EqualTo (2)); });
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 //TODO: we should check the color of the button
//var buttonTextColor = GetProperty<Color> ("btnChangeStatus", Button.BackgroundColorProperty); //var buttonTextColor = GetProperty<Color> ("btnChangeStatus", Button.BackgroundColorProperty);
//Assert.AreEqual (Color.Pink, buttonTextColor); //Assert.AreEqual (Color.Pink, buttonTextColor);

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

@ -119,7 +119,7 @@ namespace Xamarin.Forms.Controls.Issues
}; };
foreach(var view in imageControls) foreach (var view in imageControls)
{ {
view.BackgroundColor = Color.Red; view.BackgroundColor = Color.Red;
} }
@ -228,7 +228,7 @@ namespace Xamarin.Forms.Controls.Issues
SetupTest(nameof(ListView), fileSource); SetupTest(nameof(ListView), fileSource);
var imageVisible = var imageVisible =
RunningApp.RetryUntilPresent(GetImage, 10, 2000); RunningApp.QueryUntilPresent(GetImage, 10, 2000);
Assert.AreEqual(1, imageVisible.Length); Assert.AreEqual(1, imageVisible.Length);
SetImageSourceToNull(); SetImageSourceToNull();
@ -261,7 +261,7 @@ namespace Xamarin.Forms.Controls.Issues
UITest.Queries.AppResult TestForImageVisible() UITest.Queries.AppResult TestForImageVisible()
{ {
var images = RunningApp.RetryUntilPresent(() => var images = RunningApp.QueryUntilPresent(() =>
{ {
var result = RunningApp.WaitForElement(_fileNameAutomationId); var result = RunningApp.WaitForElement(_fileNameAutomationId);

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

@ -52,7 +52,7 @@ namespace Xamarin.Forms.Controls.Issues
public void LegacyImageSourceProperties() public void LegacyImageSourceProperties()
{ {
RunningApp.WaitForElement("Nothing Crashed"); RunningApp.WaitForElement("Nothing Crashed");
RunningApp.RetryUntilPresent( RunningApp.QueryUntilPresent(
() => () =>
{ {
var result = RunningApp.WaitForElement("Image1"); var result = RunningApp.WaitForElement("Image1");

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

@ -58,7 +58,7 @@ namespace Xamarin.Forms.Controls.Issues
page1.Content = new Label { Text = "success", AutomationId = "success" }; page1.Content = new Label { Text = "success", AutomationId = "success" };
} }
catch(Exception exc) catch (Exception exc)
{ {
page1.Content = new Label { Text = $"{exc}", AutomationId = "failure" }; page1.Content = new Label { Text = $"{exc}", AutomationId = "failure" };
} }
@ -75,7 +75,7 @@ namespace Xamarin.Forms.Controls.Issues
[Test] [Test]
public void Issue6286_WebView_Test() public void Issue6286_WebView_Test()
{ {
RunningApp.RetryUntilPresent(() => RunningApp.WaitForElement("success")); RunningApp.QueryUntilPresent(() => RunningApp.WaitForElement("success"));
} }
#endif #endif
} }

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

@ -6,11 +6,11 @@ using Xamarin.UITest.Queries;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading; using System.Threading;
namespace Xamarin.Forms.Core.UITests namespace Xamarin.UITest
{ {
internal static class AppExtensions internal static class AppExtensions
{ {
public static T[] RetryUntilPresent<T>( public static T[] QueryUntilPresent<T>(
this IApp app, this IApp app,
Func<T[]> func, Func<T[]> func,
int retryCount = 10, int retryCount = 10,
@ -28,7 +28,13 @@ namespace Xamarin.Forms.Core.UITests
return results; return results;
} }
}
}
namespace Xamarin.Forms.Core.UITests
{
internal static class AppExtensions
{
public static AppRect ScreenBounds(this IApp app) public static AppRect ScreenBounds(this IApp app)
{ {
return app.Query(Queries.Root()).First().Rect; return app.Query(Queries.Root()).First().Rect;