Skip to content

Commit

Permalink
Run multiple UI tests without restarting ControlGallery (xamarin#539)
Browse files Browse the repository at this point in the history
* Allow UI tests to bypass "manual" navigation to isses pages

* Add missing Preserve attribute

* Make Issue198 test work with direct navigation

* Remove empty UI tests

* Fix error handling for iOS

* Use navigation which works for subsequent TestNavigationPages on iOS

* Fix race condition in 39530 test
Remove master page nesting when doing direct nav for UI tests

* Set up and run a single instance of Control Gallery for UI tests

* Force NavigateToIssue to wait for main page appearing to deal with iOS timing

* Move remaining UI tests into Issues namespace

* Change the connection check URL so it'll work on iOS

* Make Appearing Gallery tests work without restarting app

* Prevent ContextActions tests from stepping on each other

* Make context menu test more robust

* Move ButtonExtensions back to Controls namespace

* Have test 774 dismiss the action sheet before ending

* Update UITest package to 2.0.0 stable

* Make 2948 restore orientation when it's done

* Null check on PageController before calling SendDisappearing

* Adding a wait for the root page in the core tests

* Add consecutive tests reset to prevent memory slog on older iOS devices
  • Loading branch information
hartez authored and Jason Smith committed Nov 16, 2016
1 parent acc6efb commit 122f0e3
Show file tree
Hide file tree
Showing 176 changed files with 781 additions and 331 deletions.
24 changes: 23 additions & 1 deletion Xamarin.Forms.ControlGallery.Android/Activity1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

using Droid = Android;
using System.Globalization;

using Java.Interop;
using Xamarin.Forms.Controls.Issues;

[assembly: Dependency (typeof (CacheService))]
[assembly: Dependency (typeof (TestCloudService))]
Expand Down Expand Up @@ -274,6 +275,12 @@ protected override void OnDestroy()
{
base.OnDestroy();
}

[Export("NavigateToTest")]
public bool NavigateToTest(string test)
{
return _app.NavigateToTestPage(test);
}
}
#else

Expand All @@ -297,6 +304,8 @@ protected override void OnDestroy()
]
public class Activity1 : FormsAppCompatActivity
{
App _app;

protected override void OnCreate (Bundle bundle)
{
ToolbarResource = Resource.Layout.Toolbar;
Expand All @@ -319,6 +328,7 @@ protected override void OnCreate (Bundle bundle)
//Forms.SetTitleBarVisibility (AndroidTitleBarVisibility.Never);

var app = new App();
_app = app;

// When the native control gallery loads up, it'll let us know so we can add the nested native controls
MessagingCenter.Subscribe<NestedNativeControlGalleryPage>(this, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);
Expand Down Expand Up @@ -446,6 +456,18 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
return null;
}
}

[Export("NavigateToTest")]
public bool NavigateToTest(string test)
{
return _app.NavigateToTestPage(test);
}

[Export("Reset")]
public void Reset()
{
_app.Reset();
}
}
#endif
}
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.ControlGallery.Android/CustomRenderers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using AView = Android.Views.View;
using Android.OS;
using System.Reflection;
using Xamarin.Forms.Controls.Issues;

[assembly: ExportRenderer(typeof(Bugzilla31395.CustomContentView), typeof(CustomContentRenderer))]
[assembly: ExportRenderer(typeof(NativeListView), typeof(NativeListViewRenderer))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Mono.Android" />
<Reference Include="Mono.Android.Export" />
<Reference Include="mscorlib" />
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
18 changes: 18 additions & 0 deletions Xamarin.Forms.ControlGallery.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.iOS;
using Xamarin.Forms.Controls;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.iOS;

[assembly: Dependency(typeof(TestCloudService))]
Expand Down Expand Up @@ -132,6 +133,7 @@ public override bool FinishedLaunching (UIApplication app, NSDictionary options)
[Register("AppDelegate")]
public partial class AppDelegate : FormsApplicationDelegate
{
App _app;

public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary launchOptions)
{
Expand All @@ -150,6 +152,7 @@ public override bool FinishedLaunching(UIApplication uiApplication, NSDictionary
};

var app = new App();
_app = app;

// When the native control gallery loads up, it'll let us know so we can add the nested native controls
MessagingCenter.Subscribe<NestedNativeControlGalleryPage>(this, NestedNativeControlGalleryPage.ReadyForNativeControlsMessage, AddNativeControls);
Expand Down Expand Up @@ -352,6 +355,21 @@ public void StartPressed40911()
}

#endregion

[Export("navigateToTest:")]
public string NavigateToTest(string test)
{
// According to https://developer.xamarin.com/guides/testcloud/uitest/working-with/backdoors/
// this method has to return a string
return _app.NavigateToTestPage(test).ToString();
}

[Export("reset:")]
public string Reset(string str)
{
_app.Reset();
return String.Empty;
}
}

[Register("KVOUISlider")]
Expand Down
1 change: 1 addition & 0 deletions Xamarin.Forms.ControlGallery.iOS/CustomRenderers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Xamarin.Forms;
using Xamarin.Forms.ControlGallery.iOS;
using Xamarin.Forms.Controls;
using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.Platform.iOS;
using RectangleF = CoreGraphics.CGRect;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

namespace Xamarin.Forms.Controls
{

public class PropertyChangedBase : INotifyPropertyChanged
{
Dictionary<string, object> _properties = new Dictionary<string, object>();
Expand Down Expand Up @@ -312,11 +311,16 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
}
}

[Preserve (AllMembers = true)]
[Issue (IssueTracker.None, 0, "Adding Multiple Items to a ListView", PlatformAffected.All)]

}

namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.None, 0, "Adding Multiple Items to a ListView", PlatformAffected.All)]
public class AddingMultipleItemsListView : TestContentPage
{
protected override void Init ()
protected override void Init()
{
Title = "Hours";
var exampleViewModel = new ExampleViewModel();
Expand Down Expand Up @@ -351,36 +355,39 @@ protected override void Init ()
Children = {
listView,
addOneJobButton,
addTwoJobsButton
addTwoJobsButton
}
};
Content = layout;
}

[Preserve (AllMembers = true)]
[Preserve(AllMembers = true)]
public class CustomViewCell : ViewCell
{
public CustomViewCell ()
public CustomViewCell()
{
var jobId = new Label {
var jobId = new Label
{
#pragma warning disable 618
Font = Font.SystemFontOfSize(20),
#pragma warning restore 618
WidthRequest = 105,
VerticalOptions = LayoutOptions.Center,

HorizontalOptions = LayoutOptions.StartAndExpand
};
};
jobId.SetBinding(Label.TextProperty, "JobId");

var jobName = new Label {
var jobName = new Label
{
VerticalOptions = LayoutOptions.Center,
WidthRequest = 175,
HorizontalOptions = LayoutOptions.CenterAndExpand,
};
jobName.SetBinding(Label.TextProperty, "JobName");

var hours = new Label {
var hours = new Label
{
WidthRequest = 45,
VerticalOptions = LayoutOptions.Center,
#pragma warning disable 618
Expand All @@ -391,8 +398,9 @@ public CustomViewCell ()
};
hours.SetBinding(Label.TextProperty, new Binding("Hours", BindingMode.OneWay, new DoubleStringConverter()));

var hlayout = new StackLayout {
Children = {
var hlayout = new StackLayout
{
Children = {
jobId,
jobName,
hours
Expand All @@ -403,45 +411,45 @@ public CustomViewCell ()
View = hlayout;
}
}

#if UITEST
[Test]
public void AddingMultipleListViewTests1AllElementsPresent ()
public void AddingMultipleListViewTests1AllElementsPresent()
{
RunningApp.WaitForElement (q => q.Marked ("Big Job"));
RunningApp.WaitForElement (q => q.Marked ("Smaller Job"));
RunningApp.WaitForElement (q => q.Marked ("Add On Job"));
RunningApp.WaitForElement (q => q.Marked ("Add One"));
RunningApp.WaitForElement (q => q.Marked ("Add Two"));
RunningApp.WaitForElement (q => q.Marked ("3672"));
RunningApp.WaitForElement (q => q.Marked ("6289"));
RunningApp.WaitForElement (q => q.Marked ("3672-41"));
RunningApp.WaitForElement (q => q.Marked ("2"));
RunningApp.WaitForElement (q => q.Marked ("2"));
RunningApp.WaitForElement (q => q.Marked ("23"));

RunningApp.Screenshot ("All elements are present");
RunningApp.WaitForElement(q => q.Marked("Big Job"));
RunningApp.WaitForElement(q => q.Marked("Smaller Job"));
RunningApp.WaitForElement(q => q.Marked("Add On Job"));
RunningApp.WaitForElement(q => q.Marked("Add One"));
RunningApp.WaitForElement(q => q.Marked("Add Two"));
RunningApp.WaitForElement(q => q.Marked("3672"));
RunningApp.WaitForElement(q => q.Marked("6289"));
RunningApp.WaitForElement(q => q.Marked("3672-41"));
RunningApp.WaitForElement(q => q.Marked("2"));
RunningApp.WaitForElement(q => q.Marked("2"));
RunningApp.WaitForElement(q => q.Marked("23"));

RunningApp.Screenshot("All elements are present");
}

[Test]
public void AddingMultipleListViewTests2AddOneElementToList ()
public void AddingMultipleListViewTests2AddOneElementToList()
{
RunningApp.Tap (q => q.Marked ("Add One"));
RunningApp.Tap(q => q.Marked("Add One"));

RunningApp.WaitForElement (q => q.Marked ("1234"), timeout: TimeSpan.FromSeconds (2));
RunningApp.Screenshot ("One more element exists");
RunningApp.WaitForElement(q => q.Marked("1234"), timeout: TimeSpan.FromSeconds(2));
RunningApp.Screenshot("One more element exists");
}

[Test]
public void AddingMultipleListViewTests3AddTwoElementToList ()
public void AddingMultipleListViewTests3AddTwoElementToList()
{
RunningApp.Screenshot ("Click 'Add Two'");
RunningApp.Tap (q => q.Marked ("Add Two"));
RunningApp.Screenshot("Click 'Add Two'");
RunningApp.Tap(q => q.Marked("Add Two"));

RunningApp.WaitForElement (q => q.Marked ("9999"), timeout: TimeSpan.FromSeconds (2));
RunningApp.WaitForElement (q => q.Marked ("8888"), timeout: TimeSpan.FromSeconds (2));
RunningApp.Screenshot ("Two more element exist");
RunningApp.WaitForElement(q => q.Marked("9999"), timeout: TimeSpan.FromSeconds(2));
RunningApp.WaitForElement(q => q.Marked("8888"), timeout: TimeSpan.FromSeconds(2));
RunningApp.Screenshot("Two more element exist");
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
namespace Xamarin.Forms.Controls.Issues
{
[Preserve(AllMembers = true)]
[Issue(IssueTracker.Bugzilla, 21177, "Using a UICollectionView in a ViewRenderer results in issues with selection")]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Collections.Generic;
using System.Linq;

using Xamarin.Forms.Controls.Issues;
using Xamarin.Forms.CustomAttributes;
using Xamarin.Forms.Internals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 24574, "Tap Double Tap")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 25979, "https://bugzilla.xamarin.com/show_bug.cgi?id=25979")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<local:TestContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Xamarin.Forms.Controls"
x:Class="Xamarin.Forms.Controls.Bugzilla26032">
x:Class="Xamarin.Forms.Controls.Issues.Bugzilla26032">
<RelativeLayout>
<ListView x:Name="List1"
RelativeLayout.XConstraint="{ConstraintExpression Type=Constant, Constant=0}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.ListView)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 26171, "Xamarin.Forms.Maps is not updating VisibleRegion property when layout is changed")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using Xamarin.Forms.Core.UITests;
#endif

namespace Xamarin.Forms.Controls
namespace Xamarin.Forms.Controls.Issues
{
#if UITEST
[Category(UITestCategories.ListView)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
using Xamarin.UITest;
#endif

namespace Xamarin.Forms.Controls.TestCasesPages
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers = true)]
public class FamilyViewModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
using NUnit.Framework;
#endif

namespace Xamarin.Forms.Controls
namespace Xamarin.Forms.Controls.Issues
{
[Preserve (AllMembers = true)]
[Issue (IssueTracker.Bugzilla, 26993, "https://bugzilla.xamarin.com/show_bug.cgi?id=26993")]
Expand All @@ -17,7 +17,7 @@ public class Bugzilla26993 : TestContentPage // or TestMasterDetailPage, etc ...
[Preserve (AllMembers = true)]
public class Bz26993ViewCell : ViewCell
{
static int s_id = 0;
public static int s_id = 0;

public Bz26993ViewCell ()
{
Expand All @@ -33,6 +33,8 @@ public Bz26993ViewCell ()

protected override void Init ()
{
Bz26993ViewCell.s_id = 0;

var itemSource = new List<string> {
"",
"",
Expand Down
Loading

0 comments on commit 122f0e3

Please sign in to comment.