Ejemplo n.º 1
0
        /// <summary>
        /// Checks the selected property of an element using the given parameters.
        /// </summary>
        /// <returns><see langword="true"/> if the element selected property equals the given parameter, otherwise <see langword="false"/>.</returns>
        public static bool IsElementSelected(AppiumWebElement element, bool selected = true)
        {
            var wait = new WebDriverWait(GlobalVar.AndroidDriver, TimeSpan.FromSeconds(GlobalVar.TimeSpan));

            try
            {
                return(wait.Until(driver => ExpectedConditions.ElementSelected(element, selected)));
            }
            catch (Exception ex)
            {
                Assert.Fail("IsElementSelected threw an exception: " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Checks if an element is not displayed using the text of an element.
        /// </summary>
        /// <param name="by">Searcher of type By.</param>
        /// <param name="text">text to match an element.</param>
        /// <returns><see langword="true"/> when the element is displayed, otherwise <see langword="false"/>.</returns>
        public static bool IsElementNotDisplayed(By by, string text)
        {
            var wait = new WebDriverWait(GlobalVar.AndroidDriver, TimeSpan.FromSeconds(GlobalVar.TimeSpan));

            try
            {
                return(wait.Until(driver => ExpectedConditions.InvisibilityOfElementWithText(by, text)));
            }
            catch (Exception ex)
            {
                Assert.Fail("IsElementNotDisplayed threw an exception: " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Check if the given parameter is the same as the app title.
        /// </summary>
        /// <param name="title">Title of the app to be match.</param>
        /// <returns><see langword="true"/> when the screen Title matches the given title, otherwise <see langword="false"/>.</returns>
        public static bool AppTitleMatch(string title)
        {
            var wait = new WebDriverWait(GlobalVar.AndroidDriver, TimeSpan.FromSeconds(GlobalVar.TimeSpan));

            try
            {
                return(wait.Until(driver => ExpectedConditions.TitleIs(title)));
            }
            catch (Exception ex)
            {
                Assert.Fail("AppTitleMatch threw an exception: " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Finds all the element that are visible on a screen.
        /// </summary>
        /// <param name="by">Searcher of type By.</param>
        /// <returns>The list of <see cref="AppiumWebElement"/> once it is located.</returns>
        public static IEnumerable <AppiumWebElement> GetVisibleElements(By by)
        {
            var wait = new WebDriverWait(GlobalVar.AndroidDriver, TimeSpan.FromSeconds(GlobalVar.TimeSpan));

            try
            {
                return(wait.Until(driver => ExpectedConditions.VisibilityOfAllElements(by)));
            }
            catch (Exception ex)
            {
                Assert.Fail("GetVisibleElements threw an exception: " + ex.Message);
                return(null);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Send the input text to a corresponding element.
        /// </summary>
        /// <param name="by">Searcher of type By.</param>
        /// <param name="inputText">Text to be input over an element.</param>
        /// <returns><see langword="true"/> if the element selected property equals the given parameter, otherwise <see langword="false"/>.</returns>
        public static void SendKeys(By by, string inputText)
        {
            var wait = new WebDriverWait(GlobalVar.AndroidDriver, TimeSpan.FromSeconds(GlobalVar.TimeSpan));

            try
            {
                var element = wait.Until(driver => ExpectedConditions.ElementToBeClickable(by));
                element.Clear();
                element.SendKeys(inputText);
            }
            catch (Exception ex)
            {
                Assert.Fail("SendKeys threw an exception: " + ex.Message);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Checks if an element is enabled.
        /// </summary>
        /// <param name="by">Searcher of type By.</param>
        /// <returns><see langword="true"/> when the element is enabled, otherwise <see langword="false"/>.</returns>
        public static bool IsElementEnabled(By by)
        {
            var wait = new WebDriverWait(GlobalVar.AndroidDriver, TimeSpan.FromSeconds(GlobalVar.TimeSpan));

            try
            {
                var element = wait.Until(driver => ExpectedConditions.ElementExists(by));
                return(element.Enabled);
            }
            catch (Exception ex)
            {
                Assert.Fail("IsElementEnabled threw an exception: " + ex.Message);
                return(false);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Get the Rectangle of a specific element.
        /// </summary>
        /// <param name="by">Searcher of type By.</param>
        /// <returns>The <see cref="Rectangle"/> of an element once it is located.</returns>
        public static Rectangle GetElementRect(By by)
        {
            var wait = new WebDriverWait(GlobalVar.AndroidDriver, TimeSpan.FromSeconds(GlobalVar.TimeSpan));

            try
            {
                var element = wait.Until(driver => ExpectedConditions.ElementIsVisible(by));
                return(element.Rect);
            }
            catch (Exception ex)
            {
                Assert.Fail("GetElementRect threw an exception: " + ex.Message);
                return(Rectangle.Empty);
            }
        }