#if UITEST using System; using System.IO; using Xamarin.UITest; using Xamarin.UITest.Queries; namespace Xamarin.Forms.Controls { /// /// Decorator for IApp which only takes screenshots if the SCREENSHOTS symbol is specified /// internal class ScreenshotConditionalApp : IApp { readonly IApp _app; public ScreenshotConditionalApp(IApp app) { _app = app; } public AppResult[] Query(Func query = null) { return _app.Query(query); } public AppResult[] Query(string marked) { return _app.Query(marked); } public AppWebResult[] Query(Func query) { return _app.Query(query); } public T[] Query(Func> query) { return _app.Query(query); } public string[] Query(Func query) { return _app.Query(query); } public AppResult[] Flash(Func query = null) { return _app.Flash(query); } public AppResult[] Flash(string marked) { return _app.Flash(marked); } public void EnterText(string text) { _app.EnterText(text); } public void EnterText(Func query, string text) { _app.EnterText(query, text); } public void EnterText(string marked, string text) { _app.EnterText(marked, text); } public void EnterText(Func query, string text) { _app.EnterText(query, text); } public void ClearText(Func query) { _app.ClearText(query); } public void ClearText(Func query) { _app.ClearText(query); } public void ClearText(string marked) { _app.ClearText(marked); } public void ClearText() { _app.ClearText(); } public void PressEnter() { _app.PressEnter(); } public void DismissKeyboard() { _app.DismissKeyboard(); } public void Tap(Func query) { _app.Tap(query); } public void Tap(string marked) { _app.Tap(marked); } public void Tap(Func query) { _app.Tap(query); } public void TapCoordinates(float x, float y) { _app.TapCoordinates(x, y); } public void TouchAndHold(Func query) { _app.TouchAndHold(query); } public void TouchAndHold(string marked) { _app.TouchAndHold(marked); } public void TouchAndHoldCoordinates(float x, float y) { _app.TouchAndHoldCoordinates(x, y); } public void DoubleTap(Func query) { _app.DoubleTap(query); } public void DoubleTap(string marked) { _app.DoubleTap(marked); } public void DoubleTapCoordinates(float x, float y) { _app.DoubleTapCoordinates(x, y); } public void PinchToZoomIn(Func query, TimeSpan? duration = null) { _app.PinchToZoomIn(query, duration); } public void PinchToZoomIn(string marked, TimeSpan? duration = null) { _app.PinchToZoomIn(marked, duration); } public void PinchToZoomInCoordinates(float x, float y, TimeSpan? duration) { _app.PinchToZoomInCoordinates(x, y, duration); } public void PinchToZoomOut(Func query, TimeSpan? duration = null) { _app.PinchToZoomOut(query, duration); } public void PinchToZoomOut(string marked, TimeSpan? duration = null) { _app.PinchToZoomOut(marked, duration); } public void PinchToZoomOutCoordinates(float x, float y, TimeSpan? duration) { _app.PinchToZoomOutCoordinates(x, y, duration); } public void WaitFor(Func predicate, string timeoutMessage = "Timed out waiting...", TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null) { _app.WaitFor(predicate, timeoutMessage, timeout, retryFrequency, postTimeout); } public AppResult[] WaitForElement(Func query, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null) { return _app.WaitForElement(query, timeoutMessage, timeout, retryFrequency, postTimeout); } public AppResult[] WaitForElement(string marked, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null) { return _app.WaitForElement(marked, timeoutMessage, timeout, retryFrequency, postTimeout); } public AppWebResult[] WaitForElement(Func query, string timeoutMessage = "Timed out waiting for element...", TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null) { return _app.WaitForElement(query, timeoutMessage, timeout, retryFrequency, postTimeout); } public void WaitForNoElement(Func query, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null) { _app.WaitForNoElement(query, timeoutMessage, timeout, retryFrequency, postTimeout); } public void WaitForNoElement(string marked, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null) { _app.WaitForNoElement(marked, timeoutMessage, timeout, retryFrequency, postTimeout); } public void WaitForNoElement(Func query, string timeoutMessage = "Timed out waiting for no element...", TimeSpan? timeout = null, TimeSpan? retryFrequency = null, TimeSpan? postTimeout = null) { _app.WaitForNoElement(query, timeoutMessage, timeout, retryFrequency, postTimeout); } public FileInfo Screenshot(string title) { #if SCREENSHOTS return _app.Screenshot(title); #else return null; #endif } public void SwipeRight() { #pragma warning disable 618 _app.SwipeRight(); #pragma warning restore 618 } public void SwipeLeftToRight(double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeLeftToRight(swipePercentage, swipeSpeed, withInertia); } public void SwipeLeftToRight(string marked, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeLeftToRight(marked, swipePercentage, swipeSpeed, withInertia); } public void SwipeLeft() { #pragma warning disable 618 _app.SwipeLeft(); #pragma warning restore 618 } public void SwipeRightToLeft(double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeRightToLeft(swipePercentage, swipeSpeed, withInertia); } public void SwipeRightToLeft(string marked, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeRightToLeft(marked, swipePercentage, swipeSpeed, withInertia); } public void SwipeLeftToRight(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeLeftToRight(query, swipePercentage, swipeSpeed, withInertia); } public void SwipeLeftToRight(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeLeftToRight(query, swipePercentage, swipeSpeed, withInertia); } public void SwipeRightToLeft(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeRightToLeft(query, swipePercentage, swipeSpeed, withInertia); } public void SwipeRightToLeft(Func query, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.SwipeRightToLeft(query, swipePercentage, swipeSpeed, withInertia); } public void ScrollUp(Func query = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.ScrollUp(query, strategy, swipePercentage, swipeSpeed, withInertia); } public void ScrollUp(string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.ScrollUp(withinMarked, strategy, swipePercentage, swipeSpeed, withInertia); } public void ScrollDown(Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.ScrollDown(withinQuery, strategy, swipePercentage, swipeSpeed, withInertia); } public void ScrollDown(string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true) { _app.ScrollDown(withinMarked, strategy, swipePercentage, swipeSpeed, withInertia); } public void ScrollTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollTo(toMarked, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollUpTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollUpTo(toMarked, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollUpTo(Func toQuery, string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollUpTo(toQuery, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollDownTo(string toMarked, string withinMarked = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollDownTo(toMarked, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollDownTo(Func toQuery, string withinMarked, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollDownTo(toQuery, withinMarked, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollUpTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollUpTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollUpTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollUpTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollDownTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollDownTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void ScrollDownTo(Func toQuery, Func withinQuery = null, ScrollStrategy strategy = ScrollStrategy.Auto, double swipePercentage = 0.67, int swipeSpeed = 500, bool withInertia = true, TimeSpan? timeout = null) { _app.ScrollDownTo(toQuery, withinQuery, strategy, swipePercentage, swipeSpeed, withInertia, timeout); } public void SetOrientationPortrait() { _app.SetOrientationPortrait(); } public void SetOrientationLandscape() { _app.SetOrientationLandscape(); } public void Repl() { _app.Repl(); } public void Back() { _app.Back(); } public void PressVolumeUp() { _app.PressVolumeUp(); } public void PressVolumeDown() { _app.PressVolumeDown(); } public object Invoke(string methodName, object argument = null) { return _app.Invoke(methodName, argument); } public object Invoke(string methodName, object[] arguments) { return _app.Invoke(methodName, arguments); } public void DragCoordinates(float fromX, float fromY, float toX, float toY) { _app.DragCoordinates(fromX, fromY, toX, toY); } public void DragAndDrop(Func @from, Func to) { _app.DragAndDrop(@from, to); } public void DragAndDrop(string @from, string to) { _app.DragAndDrop(@from, to); } public void SetSliderValue(string marked, double value) { _app.SetSliderValue(marked, value); } public void SetSliderValue(Func query, double value) { _app.SetSliderValue(query, value); } public AppPrintHelper Print { get { return _app.Print; } } public IDevice Device { get { return _app.Device; } } public ITestServer TestServer { get { return _app.TestServer; } } } } #endif