Beispiel #1
0
 /// <summary>
 /// Waits until the <see cref="AppDriver"/> is ready.
 /// </summary>
 /// <param name="appDriver">
 /// The <see cref="AppDriver"/> on which to executor the command.
 /// </param>
 public static void WaitUntilReady(this AppDriver appDriver)
 {
     while (!appDriver.IsReady())
     {
         Thread.Sleep(1000);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Dismisses the the keyboard.
 /// </summary>
 /// <param name="appDriver">
 /// The <see cref="AppDriver"/> on which to executor the command.
 /// </param>
 public static void DismissKeyboard(this AppDriver appDriver)
 {
     appDriver.ExecuteCommand(AppDriverCommand.DismissKeyboard, new Dictionary <string, object>()
     {
         { AppDriverCommand.SessionId, appDriver.SessionId }
     });
 }
Beispiel #3
0
 /// <summary>
 /// Clears the text of the active text field.
 /// </summary>
 /// <param name="appDriver">
 /// The <see cref="AppDriver"/> on which to executor the command.
 /// </param>
 public static void ClearText(this AppDriver appDriver)
 {
     appDriver.ExecuteCommand(AppDriverCommand.ClearText, new Dictionary <string, object>()
     {
         { AppDriverCommand.SessionId, appDriver.SessionId }
     });
 }
Beispiel #4
0
        /// <summary>
        /// Executes a command on the given <see cref="AppDriver"/>
        /// </summary>
        /// <param name="appDriver">
        /// The <see cref="AppDriver"/> on which to executor the command.
        /// </param>
        /// <param name="name">
        /// The name of the command.
        /// </param>
        /// <param name="parameters">
        /// The parameters of the command.
        /// </param>
        /// <returns>
        /// The response of the execution.
        /// </returns>
        private static Response ExecuteCommand(this AppDriver appDriver, string name, Dictionary <string, object> parameters)
        {
            var command  = new Command(appDriver.SessionId, name, parameters);
            var response = appDriver.GetCommandExecutor().Execute(command);

            return(response);
        }
Beispiel #5
0
        /// <summary>
        /// Executes a command on the given <see cref="AppDriver"/>
        /// </summary>
        /// <param name="appDriver">
        /// The <see cref="AppDriver"/> on which to executor the command.
        /// </param>
        /// <param name="name">
        /// The name of the command.
        /// </param>
        /// <param name="jsonParameters">
        /// The parameters of the command.
        /// </param>
        /// <returns>
        /// The response of the execution.
        /// </returns>
        private static Response ExecuteCommand(this AppDriver appDriver, string name, string jsonParameters)
        {
            var command  = new Command(name, jsonParameters);
            var response = appDriver.GetCommandExecutor().Execute(command);

            return(response);
        }
Beispiel #6
0
        public static Timeouts GetTimeouts(this AppDriver appDriver)
        {
            var response = appDriver.ExecuteCommand(AppDriverCommand.GetTimeouts, new Dictionary <string, object>()
            {
                { AppDriverCommand.SessionId, appDriver.SessionId }
            });

            return(GetValue <Timeouts>(response));
        }
Beispiel #7
0
 /// <summary>
 /// Clicks on the device screen on the given absolute coordinate.
 /// </summary>
 /// <param name="appDriver">
 /// The <see cref="AppDriver"/> on which to execute the command.
 /// </param>
 /// <param name="x">
 /// The x component of the coordinate.
 /// </param>
 /// <param name="y">
 /// The y component of the coordinate.
 /// </param>
 public static void ClickByCoordinate(this AppDriver appDriver, int x, int y)
 {
     appDriver.ExecuteCommand(AppDriverCommand.ClickByCoordinate, new Dictionary <string, object>()
     {
         { AppDriverCommand.SessionId, appDriver.SessionId },
         { "x", x },
         { "y", y }
     });
 }
Beispiel #8
0
        public static void Flick(this AppDriver appDriver, IWebElement element, Direction direction)
        {
            var remoteWebElementType = typeof(RemoteWebElement);
            var elementIdField       = remoteWebElementType.GetField("elementId", BindingFlags.Instance | BindingFlags.NonPublic);
            var elementId            = elementIdField.GetValue(element) as string;

            appDriver.ExecuteCommand(AppDriverCommand.FlickCoordinate, new Dictionary <string, object>()
            {
                { "element", elementId },
                { "direction", direction }
            });
        }
Beispiel #9
0
        public static void ScrollToVisible(this AppDriver appDriver, IWebElement element)
        {
            var remoteWebElementType = typeof(RemoteWebElement);
            var elementIdField       = remoteWebElementType.GetField("elementId", BindingFlags.Instance | BindingFlags.NonPublic);
            var elementId            = elementIdField.GetValue(element) as string;

            appDriver.ExecuteCommand(AppDriverCommand.ScrollToVisible, new Dictionary <string, object>()
            {
                { AppDriverCommand.SessionId, appDriver.SessionId },
                { AppDriverCommand.ElementId, elementId },
            });
        }
Beispiel #10
0
        public static object PerformOperation(this AppDriver appDriver, IWebElement webElement, string operation, Collection <object> arguments)
        {
            var remoteWebElementType = typeof(RemoteWebElement);
            var elementIdField       = remoteWebElementType.GetField("elementId", BindingFlags.Instance | BindingFlags.NonPublic);
            var elementId            = elementIdField.GetValue(webElement) as string;

            return(appDriver.ExecuteCommand(AppDriverCommand.PerformOperation, new Dictionary <string, object>
            {
                { AppDriverCommand.SessionId, appDriver.SessionId },
                { AppDriverCommand.ElementId, elementId },
                { "operation", operation },
                { "args", arguments }
            }).Value);
        }
Beispiel #11
0
        public static void SetProperty(this AppDriver appDriver, IWebElement element, string name, string value)
        {
            var remoteWebElementType = typeof(RemoteWebElement);
            var elementIdField       = remoteWebElementType.GetField("elementId", BindingFlags.Instance | BindingFlags.NonPublic);
            var elementId            = elementIdField.GetValue(element) as string;

            appDriver.ExecuteCommand(AppDriverCommand.SetProperty, new Dictionary <string, object>()
            {
                { AppDriverCommand.SessionId, appDriver.SessionId },
                { AppDriverCommand.ElementId, elementId },
                { AppDriverCommand.PropertyName, name },
                { AppDriverCommand.PropertyValue, value },
            });
        }
Beispiel #12
0
        /// <summary>
        /// Scrolls until an element with the marked contition is visible.
        /// </summary>
        /// <param name="appDriver">
        /// The <see cref="AppDriver"/> on which to executor the command.
        /// </param>
        /// <param name="element">
        /// The element on which to swipe.
        /// </param>
        /// <param name="xpath">
        /// the xpath condition to stop scrolling.
        /// </param>
        public static void ScrollUpTo(this AppDriver appDriver, IWebElement element, string xpath)
        {
            var remoteWebElementType = typeof(RemoteWebElement);
            var elementIdField       = remoteWebElementType.GetField("elementId", BindingFlags.Instance | BindingFlags.NonPublic);
            var elementId            = elementIdField.GetValue(element) as string;

            appDriver.ExecuteCommand(AppDriverCommand.ScrollTo, new Dictionary <string, object>()
            {
                { AppDriverCommand.SessionId, appDriver.SessionId },
                { AppDriverCommand.ElementId, elementId },
                { "value", xpath },
                { "using", "xpath" },
                { "direction", "Down" }
            });
        }
Beispiel #13
0
        public static void FlickCoordinate(this AppDriver appDriver, IWebElement element, int x, int y, int xOffset, int yOffset, int speed)
        {
            var remoteWebElementType = typeof(RemoteWebElement);
            var elementIdField       = remoteWebElementType.GetField("elementId", BindingFlags.Instance | BindingFlags.NonPublic);
            var elementId            = elementIdField.GetValue(element) as string;

            appDriver.ExecuteCommand(AppDriverCommand.FlickCoordinate, new Dictionary <string, object>()
            {
                { "element", elementId },
                { "xCoordinate", x },
                { "yCoordinate", y },
                { "xoffset", xOffset },
                { "yoffset", yOffset },
                { "speed", speed },
            });
        }
Beispiel #14
0
        public static string GetDeviceId(this AppDriver appDriver)
        {
            var capabilities = appDriver.Capabilities as ICapabilities;

            return(capabilities?.GetCapability("deviceId").ToString());
        }
Beispiel #15
0
        /// <summary>
        /// Checks if the <see cref="AppDriver"/> is ready.
        /// </summary>
        /// <param name="appDriver">
        /// The <see cref="AppDriver"/> on which to executor the command.
        /// </param>
        /// <returns>
        /// <see langword="true"/> if the <see cref="AppDriver"/> is ready;
        /// otherwise, returns <see langword="false"/>
        /// </returns>
        public static bool IsReady(this AppDriver appDriver)
        {
            var response = appDriver.ExecuteCommand(AppDriverCommand.IsReady, new Dictionary <string, object>());

            return((bool)response.Value);
        }
Beispiel #16
0
 public static bool TestElementsByClassChain(this AppDriver appDriver, string value)
 {
     return(appDriver.TestElements(AppDriver.ClassChain, value));
 }
Beispiel #17
0
 public static bool TestElementsByPredicateString(this AppDriver appDriver, string value)
 {
     return(appDriver.TestElements(AppDriver.PredicateString, value));
 }
Beispiel #18
0
 public static ReadOnlyCollection <IWebElement> FindElementsByClassChain(this AppDriver appDriver, string value)
 {
     return(appDriver.FindElements(AppDriver.ClassChain, value));
 }
Beispiel #19
0
 public static IWebElement FindElementByClassChain(this AppDriver appDriver, string value)
 {
     return(appDriver.FindElement(AppDriver.ClassChain, value));
 }
Beispiel #20
0
 public static ReadOnlyCollection <IWebElement> FindElementsByPredicateString(this AppDriver appDriver, string value)
 {
     return(appDriver.FindElements(AppDriver.PredicateString, value));
 }
Beispiel #21
0
 public static IWebElement FindElementByPredicateString(this AppDriver appDriver, string value)
 {
     return(appDriver.FindElement(AppDriver.PredicateString, value));
 }
Beispiel #22
0
        /// <summary>
        /// Executes a command on the given <see cref="AppDriver"/>
        /// </summary>
        /// <typeparam name="T">
        /// The response type
        /// </typeparam>
        /// <param name="appDriver">
        /// The <see cref="AppDriver"/> on which to executor the command.
        /// </param>
        /// <param name="name">
        /// The name of the command.
        /// </param>
        /// <param name="parameters">
        /// The parameters of the command.
        /// </param>
        /// <returns>
        /// The response of the execution.
        /// </returns>
        private static T ExecuteCommand <T>(this AppDriver appDriver, string name, Dictionary <string, object> parameters)
        {
            var command = new Command(appDriver.SessionId, name, parameters);

            return(appDriver.GetCommandExecutor().Execute <T>(command));
        }
Beispiel #23
0
 /// <summary>
 /// Finds an element based on the marked meta tag. An element corresponds to the marked meta tag if the text property or the element id equals the tag value.
 /// </summary>
 /// <param name="appDriver">
 /// The <see cref="AppDriver"/> on which to executor the command.
 /// </param>
 /// <param name="marked">
 /// The marked meta tag.
 /// </param>
 /// <returns>
 /// The element matching the marked meta tag.
 /// </returns>
 public static IWebElement FindElementByMarked(this AppDriver appDriver, string marked)
 {
     return(appDriver.FindElement(By.XPath($"*[@marked='{marked}']")));
 }
Beispiel #24
0
        /// <summary>
        /// Executes a command on the given <see cref="AppDriver"/>
        /// </summary>
        /// <typeparam name="T">
        /// The response type
        /// </typeparam>
        /// <param name="appDriver">
        /// The <see cref="AppDriver"/> on which to executor the command.
        /// </param>
        /// <param name="name">
        /// The name of the command.
        /// </param>
        /// <param name="jsonParameters">
        /// The parameters of the command.
        /// </param>
        /// <returns>
        /// The response of the execution.
        /// </returns>
        private static T ExecuteCommand <T>(this AppDriver appDriver, string name, string jsonParameters)
        {
            var command = new Command(name, jsonParameters);

            return(appDriver.GetCommandExecutor().Execute <T>(command));
        }
Beispiel #25
0
        /// <summary>
        /// Gets the <c>WebDriver</c> status
        /// </summary>
        /// <param name="appDriver">
        /// The <see cref="AppDriver"/> on which to executor the command.
        /// </param>
        /// <returns>
        /// The <c>WebDriver</c> status
        /// </returns>
        public static Status GetStatus(this AppDriver appDriver)
        {
            var response = appDriver.ExecuteCommand(AppDriverCommand.GetStatus, string.Empty);

            return(GetValue <Status>(response));
        }