summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Core.iOS.UITests/Remotes
diff options
context:
space:
mode:
Diffstat (limited to 'Xamarin.Forms.Core.iOS.UITests/Remotes')
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/Remotes/BaseViewContainerRemote.cs315
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/Remotes/EventViewContainerRemote.cs20
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/Remotes/LayeredViewContainerRemote.cs25
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/Remotes/RemoteFactory.cs56
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/Remotes/StateViewContainerRemote.cs35
-rw-r--r--Xamarin.Forms.Core.iOS.UITests/Remotes/ViewContainerRemote.cs13
6 files changed, 464 insertions, 0 deletions
diff --git a/Xamarin.Forms.Core.iOS.UITests/Remotes/BaseViewContainerRemote.cs b/Xamarin.Forms.Core.iOS.UITests/Remotes/BaseViewContainerRemote.cs
new file mode 100644
index 00000000..f51782ce
--- /dev/null
+++ b/Xamarin.Forms.Core.iOS.UITests/Remotes/BaseViewContainerRemote.cs
@@ -0,0 +1,315 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Runtime.Remoting.Messaging;
+using System.Security.Permissions;
+
+using NUnit.Framework;
+
+using Xamarin.UITest;
+using Xamarin.UITest.Queries;
+using Xamarin.UITest.Android;
+using Xamarin.UITest.iOS;
+using System.Globalization;
+
+
+namespace Xamarin.Forms.Core.UITests
+{
+ internal abstract class BaseViewContainerRemote
+ {
+ bool requiresDismissal;
+
+ protected IApp App { get; private set; }
+
+ public string ViewQuery { get; private set; }
+
+ public string PlatformViewType { get; set; }
+
+ public string ContainerQuery { get; private set; }
+ public string ContainerDescendents { get; private set; }
+
+ public string EventLabelQuery { get; set; }
+
+ public string StateLabelQuery { get; private set; }
+ public string StateButtonQuery { get; private set; }
+
+ public string LayeredHiddenButtonQuery { get; private set; }
+ public string LayeredLabelQuery { get; private set; }
+
+ protected BaseViewContainerRemote (IApp app, Enum formsType, string platformViewType)
+ {
+ App = app;
+ PlatformViewType = platformViewType;
+
+ // Currently tests are failing because the ViewInitilized is setting the renderer and control, fix and then remove index one
+
+ ContainerQuery = string.Format("* marked:'{0}Container'", formsType);
+ ContainerDescendents = string.Format("* marked:'{0}Container' child *", formsType);
+
+ ViewQuery = string.Format ("* marked:'{0}VisualElement'", formsType);
+
+ EventLabelQuery = string.Format ("* marked:'{0}EventLabel'", formsType);
+ StateLabelQuery = string.Format ("* marked:'{0}StateLabel'", formsType);
+ StateButtonQuery = string.Format ("* marked:'{0}StateButton'", formsType);
+ LayeredHiddenButtonQuery = string.Format ("* marked:'{0}LayeredHiddenButton'", formsType);
+ LayeredLabelQuery = string.Format ("* marked:'{0}LayeredLabel'", formsType);
+
+ if (platformViewType == PlatformViews.DatePicker) {
+ requiresDismissal = true;
+ }
+ }
+
+ public virtual void GoTo ([CallerMemberName] string callerMemberName = "")
+ {
+ var scrollBounds = App.Query (Queries.PageWithoutNavigationBar ()).First ().Rect;
+
+ // Scroll using gutter to the right of view, avoid scrolling inside of WebView
+ if (PlatformViewType == PlatformViews.WebView) {
+ scrollBounds = new AppRect {
+ X = scrollBounds.Width - 20,
+ CenterX = scrollBounds.Width - 10,
+ Y = scrollBounds.Y,
+ CenterY = scrollBounds.CenterY,
+ Width = 20,
+ Height = scrollBounds.Height,
+ };
+ }
+
+
+ while (true) {
+ var result = App.Query (o => o.Raw(ContainerQuery));
+ if (result.Any ())
+ break;
+ App.Tap (o => o.Raw ("* marked:'MoveNextButton'"));
+ }
+
+ //Assert.True (App.ScrollForElement (
+ // ContainerQuery, new Drag (scrollBounds, Drag.Direction.BottomToTop, Drag.DragLength.Medium)
+ //), "Failed to find element in: " + callerMemberName);
+
+ App.Screenshot ("Go to element");
+ }
+
+ public void TapView ()
+ {
+ App.Tap (q => q.Raw (ViewQuery));
+ }
+
+ public void DismissPopOver ()
+ {
+ App.Screenshot ("About to dismiss pop over");
+ App.Tap (q => q.Button ("Done"));
+ App.Screenshot ("Pop over dismissed");
+ }
+
+ public AppResult GetView ()
+ {
+ return App.Query (q => q.Raw (ViewQuery)).First ();
+ }
+
+ public AppResult[] GetViews ()
+ {
+ return App.Query (q => q.Raw (ViewQuery));
+ }
+
+ public AppResult[] GetContainerDescendants ()
+ {
+ return App.Query (q => q.Raw (ContainerDescendents));
+ }
+
+ public T GetProperty<T> (BindableProperty formProperty)
+ {
+ Tuple<string[], bool> property = formProperty.GetPlatformPropertyQuery ();
+ string[] propertyPath = property.Item1;
+ bool isOnParentRenderer = property.Item2;
+
+ var query = ViewQuery;
+ if (isOnParentRenderer &&
+ PlatformViewType != PlatformViews.BoxView &&
+ PlatformViewType != PlatformViews.Frame) {
+ query = query + " parent * index:0";
+ }
+
+ object prop = null;
+ bool found = false;
+
+ bool isEdgeCase = false;
+ if (App is AndroidApp && formProperty == View.ScaleProperty)
+ isEdgeCase = true;
+
+ if (!isEdgeCase) {
+ found =
+ MaybeGetProperty<string> (App, query, propertyPath, out prop) ||
+ MaybeGetProperty<float> (App, query, propertyPath, out prop) ||
+ MaybeGetProperty<bool> (App, query, propertyPath, out prop) ||
+ MaybeGetProperty<object> (App, query, propertyPath, out prop);
+ }
+
+
+ if (App is AndroidApp && formProperty == View.ScaleProperty) {
+ var matrix = new Matrix ();
+ matrix.M00 = App.Query (q => q.Raw (query).Invoke (propertyPath[0]).Value<float> ()).First ();
+ matrix.M11 = App.Query (q => q.Raw (query).Invoke (propertyPath[1]).Value<float> ()).First ();
+ matrix.M22 = 0.5f;
+ matrix.M33 = 1.0f;
+ return (T)((object)matrix);
+ }
+
+ if (!found || prop == null) {
+ throw new NullReferenceException ("null property");
+ }
+
+ if (prop.GetType () == typeof(T))
+ return (T)prop;
+
+ if (prop.GetType () == typeof(string) && typeof(T) == typeof(Matrix)) {
+ Matrix matrix = ParsingUtils.ParseCATransform3D ((string)prop);
+ return (T)((object)matrix);
+ }
+
+ if (typeof(T) == typeof(Color)) {
+ if (App is iOSApp) {
+ Color color = ParsingUtils.ParseUIColor ((string)prop);
+ return (T)((object)color);
+ } else {
+ uint intColor = (uint)((float)prop);
+ Color color = Color.FromUint (intColor);
+ return (T)((object)color);
+ }
+ }
+
+ if (prop.GetType () == typeof (string) && typeof(T) == typeof(Font)) {
+ if (App is iOSApp) {
+ Font font = ParsingUtils.ParseUIFont ((string)prop);
+ return (T)((object)font);
+ } else {
+
+ }
+ }
+
+ T result = default(T);
+
+ var stringToBoolConverter = new StringToBoolConverter ();
+ var floatToBoolConverter = new FloatToBoolConverter ();
+
+ if (stringToBoolConverter.CanConvertTo (prop, typeof(bool))) {
+ result = (T)stringToBoolConverter.ConvertTo (prop, typeof(bool));
+ } else if (floatToBoolConverter.CanConvertTo (prop, typeof(bool))) {
+ result = (T)floatToBoolConverter.ConvertTo (prop, typeof(bool));
+ }
+
+ return result;
+ }
+
+ static bool MaybeGetProperty<T>(IApp app, string query, string[] propertyPath, out object result)
+ {
+
+ try {
+ switch (propertyPath.Length){
+ case 1:
+ result = app.Query (q => q.Raw (query).Invoke (propertyPath[0]).Value<T> ()).First ();
+ break;
+ case 2:
+ result = app.Query (q => q.Raw (query).Invoke (propertyPath[0]).Invoke (propertyPath[1]).Value<T> ()).First ();
+ break;
+ case 3:
+ result = app.Query (q => q.Raw (query).Invoke (propertyPath[0]).Invoke (propertyPath[1]).Invoke (propertyPath[2]).Value<T> ()).First ();
+ break;
+ case 4:
+ result = app.Query (q => q.Raw (query).Invoke (propertyPath[0]).Invoke (propertyPath[1]).Invoke (propertyPath[2]).Invoke(propertyPath[3]).Value<T> ()).First ();
+ break;
+ default:
+ result = null;
+ return false;
+ }
+ }
+ catch {
+ result = null;
+ return false;
+ }
+
+ return true;
+ }
+
+ }
+
+ internal class StringToBoolConverter : TypeConverter
+ {
+ public override bool CanConvertTo (object source, Type targetType)
+ {
+ if (targetType != typeof(bool) || !(source is string))
+ return false;
+
+ var str = (string)source;
+ str = str.ToLowerInvariant ();
+
+ switch (str) {
+ case "0":
+ case "1":
+ case "false":
+ case "true":
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public override object ConvertTo (object source, Type targetType)
+ {
+ var str = (string)source;
+ str = str.ToLowerInvariant();
+
+ switch (str)
+ {
+ case "1":
+ case "true":
+ return true;
+ default:
+ return false;
+ }
+ }
+ }
+
+ internal class FloatToBoolConverter : TypeConverter
+ {
+ public override bool CanConvertTo (object source, Type targetType)
+ {
+ if (targetType != typeof(bool) || !(source is float))
+ return false;
+
+ var flt = (float)source;
+ var epsilon = 0.0001;
+ if (Math.Abs (flt - 1.0f) < epsilon || Math.Abs (flt - 0.0f) < epsilon)
+ return true;
+ else
+ return false;
+ }
+
+ public override object ConvertTo (object source, Type targetType)
+ {
+ var flt = (float)source;
+ var epsilon = 0.0001;
+ if (Math.Abs (flt - 1.0f) < epsilon)
+ return true;
+ else
+ return false;
+ }
+ }
+
+ internal abstract class TypeConverter
+ {
+ public abstract bool CanConvertTo (object source, Type targetType);
+
+ public abstract object ConvertTo (object source, Type targetType);
+ }
+
+ internal static class PlatformMethods
+ {
+ public static Tuple<string[], bool> GetPlatformPropertyQuery (this BindableProperty bindableProperty)
+ {
+ return PlatformMethodQueries.PropertyPlatformMethodDictionary[bindableProperty];
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Core.iOS.UITests/Remotes/EventViewContainerRemote.cs b/Xamarin.Forms.Core.iOS.UITests/Remotes/EventViewContainerRemote.cs
new file mode 100644
index 00000000..d603974d
--- /dev/null
+++ b/Xamarin.Forms.Core.iOS.UITests/Remotes/EventViewContainerRemote.cs
@@ -0,0 +1,20 @@
+using System;
+using System.Linq;
+
+using Xamarin.UITest;
+using Xamarin.UITest.Queries;
+
+namespace Xamarin.Forms.Core.UITests
+{
+ internal sealed class EventViewContainerRemote : BaseViewContainerRemote
+ {
+ public EventViewContainerRemote (IApp app, Enum formsType, string platformViewType)
+ : base (app, formsType, platformViewType) { }
+
+ public AppResult GetEventLabel ()
+ {
+ App.WaitForElement (q => q.Raw (EventLabelQuery));
+ return App.Query (q => q.Raw (EventLabelQuery)).First ();
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Core.iOS.UITests/Remotes/LayeredViewContainerRemote.cs b/Xamarin.Forms.Core.iOS.UITests/Remotes/LayeredViewContainerRemote.cs
new file mode 100644
index 00000000..6f6c1071
--- /dev/null
+++ b/Xamarin.Forms.Core.iOS.UITests/Remotes/LayeredViewContainerRemote.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Linq;
+using System.Security.Cryptography.X509Certificates;
+
+using Xamarin.UITest;
+using Xamarin.UITest.Queries;
+
+namespace Xamarin.Forms.Core.UITests
+{
+ internal sealed class LayeredViewContainerRemote : BaseViewContainerRemote
+ {
+ public LayeredViewContainerRemote (IApp app, Enum formsType, string platformViewType)
+ : base (app, formsType, platformViewType) {}
+
+ public AppResult GetLayeredLabel ()
+ {
+ return App.Query (q => q.Raw (LayeredLabelQuery)).First ();
+ }
+
+ public void TapHiddenButton ()
+ {
+ App.Tap (q => q.Raw (LayeredHiddenButtonQuery));
+ }
+ }
+} \ No newline at end of file
diff --git a/Xamarin.Forms.Core.iOS.UITests/Remotes/RemoteFactory.cs b/Xamarin.Forms.Core.iOS.UITests/Remotes/RemoteFactory.cs
new file mode 100644
index 00000000..ec9757ef
--- /dev/null
+++ b/Xamarin.Forms.Core.iOS.UITests/Remotes/RemoteFactory.cs
@@ -0,0 +1,56 @@
+using System;
+
+using Xamarin.UITest;
+using Xamarin.UITest.Queries;
+
+namespace Xamarin.Forms.Core.UITests
+{
+
+// Potential cleanup of Raw Queries
+// public void MyTest(IApp app)
+// {
+// var viewName = "myView";
+//
+// app.Query (x => x.Marked (viewName + " View").Parent ().Index (0).Sibling ().Index (1).Child (0).Child (0));
+//
+// app.Query (x => x.Marked (viewName + " View").Parent (0).Sibling (1).Child (0).Child (0));
+//
+// app.Query (x => x.LayeredHiddenButton ("mine").LayeredHiddenButton ("yours"));
+//
+// app.Query (x => x.LayeredHiddenButton (viewName).Parentx(4));
+//
+// app.ForAndroid (x => {
+// x.Back();
+// });
+// }
+
+
+// Potential cleanup of Raw Queries
+// make public or reflection will not pick up in REPL
+// internal static class Exts
+// {
+// public static void ForAndroid(this IApp app, Action<AndroidApp> action)
+// {
+// if (app is AndroidApp)
+// {
+// action (app as AndroidApp);
+// }
+// }
+//
+// public static AppQuery LayeredHiddenButton(this AppQuery query, string viewName)
+// {
+// if(query.QueryPlatform == QueryPlatform.Android)
+// {
+// return query.Marked (viewName + " Android View").Parent (0).Sibling (1).Child (0).Child (0);
+//
+// }
+// return query.Marked (viewName + " iOS View").Parent (0).Sibling (1).Child (0).Child (0);
+// }
+//
+// public static AppQuery Parentx(this AppQuery query, int index)
+// {
+// return query.Parent ().Index (index);
+// }
+// }
+
+}
diff --git a/Xamarin.Forms.Core.iOS.UITests/Remotes/StateViewContainerRemote.cs b/Xamarin.Forms.Core.iOS.UITests/Remotes/StateViewContainerRemote.cs
new file mode 100644
index 00000000..2d7a1172
--- /dev/null
+++ b/Xamarin.Forms.Core.iOS.UITests/Remotes/StateViewContainerRemote.cs
@@ -0,0 +1,35 @@
+´╗┐using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Linq.Expressions;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+using NUnit.Framework;
+
+using Xamarin.UITest;
+using Xamarin.UITest.Queries;
+
+namespace Xamarin.Forms.Core.UITests
+{
+ internal sealed class StateViewContainerRemote : BaseViewContainerRemote
+ {
+ public StateViewContainerRemote (IApp app, Enum formsType, string platformViewType)
+ : base(app, formsType, platformViewType) { }
+
+ public void TapStateButton ()
+ {
+ App.Screenshot ("Before state change");
+ App.Tap (q => q.Raw (StateButtonQuery));
+ App.Screenshot ("After state change");
+ }
+
+ public AppResult GetStateLabel ()
+ {
+ return App.Query (q => q.Raw (StateLabelQuery)).First ();
+ }
+ }
+}
diff --git a/Xamarin.Forms.Core.iOS.UITests/Remotes/ViewContainerRemote.cs b/Xamarin.Forms.Core.iOS.UITests/Remotes/ViewContainerRemote.cs
new file mode 100644
index 00000000..f19d3e6b
--- /dev/null
+++ b/Xamarin.Forms.Core.iOS.UITests/Remotes/ViewContainerRemote.cs
@@ -0,0 +1,13 @@
+using System;
+
+using Xamarin.UITest;
+using Xamarin.UITest.Queries;
+
+namespace Xamarin.Forms.Core.UITests
+{
+ internal sealed class ViewContainerRemote : BaseViewContainerRemote
+ {
+ public ViewContainerRemote (IApp app, Enum formsType, string platformViewType)
+ : base (app, formsType, platformViewType) { }
+ }
+} \ No newline at end of file