コード例 #1
0
        /// <summary>
        /// Busca um elemento dentro de outro pelo attribute ID, esperando até que o mesmo se encontre pronto (renderizado)
        /// </summary>
        /// <param name="customWebElement"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ICustomWebElement WaitFindByXPath(this ICustomWebElement customWebElement, string xpath)
        {
            CustomWebElement customWebelement = new CustomWebElement(() =>
            {
                return(SeleniumUtils.Wait(() => customWebElement.FindElement(By.XPath(xpath)), xpath));
            });

            return(customWebelement);
        }
コード例 #2
0
        /// <summary>
        /// Busca um elemento dentro de outro pelo seletor, esperando até que o mesmo se encontre pronto (renderizado)
        /// </summary>
        /// <param name="customWebElement"></param>
        /// <param name="selector"></param>
        /// <returns></returns>
        public static ICustomWebElement WaitFindBySelector(this ICustomWebElement customWebElement, string selector)
        {
            CustomWebElement customWebelement = new CustomWebElement(() =>
            {
                return(SeleniumUtils.Wait(() => customWebElement.FindElement(By.CssSelector(selector)), selector));
            });

            return(customWebelement);
        }
コード例 #3
0
        /// <summary>
        /// Busca um elemento dentro de outro pelo attribute ID, esperando até que o mesmo se encontre pronto (renderizado)
        /// </summary>
        /// <param name="customWebElement"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        public static ICustomWebElement WaitFindById(this ICustomWebElement customWebElement, string id)
        {
            CustomWebElement customWebelement = new CustomWebElement(() =>
            {
                return(SeleniumUtils.Wait(() => customWebElement.FindElement(By.Id(id)), id));
            });

            return(customWebelement);
        }
コード例 #4
0
        /// <summary>
        /// Encontra um elemento através de seu ID (lembrando que o ID deverá ser único na página) e aguarda até que o mesmo tenha sido renderizado
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="id"></param>
        /// <param name="maxMilliSecondsWaitTime">Tempo máximo a ser esperado até que o componente tenha sido renderizado</param>
        /// <returns></returns>
        public static ICustomWebElement WaitFindById(this IWebDriver webDriver, string id, int maxMilliSecondsWaitTime = 30000)
        {
            CustomWebElement customWebelement = new CustomWebElement(() =>
            {
                return(SeleniumUtils.Wait(() => webDriver.FindElement(By.Id(id)), id, maxMilliSecondsWaitTime));
            });

            return(customWebelement);
        }
コード例 #5
0
        /// <summary>
        /// Busca um elemento dentro de outro pelo attribute Name, esperando até que o mesmo se encontre pronto (renderizado)
        /// </summary>
        /// <param name="customWebElement"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public static ICustomWebElement WaitFindByName(this ICustomWebElement customWebElement, string name)
        {
            CustomWebElement customWebelement = new CustomWebElement(() =>
            {
                return(SeleniumUtils.Wait(() => customWebElement.FindElement(By.Name(name)), name));
            });

            return(customWebelement);
        }
コード例 #6
0
        /// <summary>
        /// Busca um elemento através de seu seletor, aguardando até que o mesmo seja renderizado com um tiemout de 30 segundos
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="selector"></param>
        /// <param name="maxMilliSecondsWaitTime">Tempo máximo a ser esperado até que o componente tenha sido renderizado</param>
        /// <returns></returns>
        public static ICustomWebElement WaitFindBySelector(this IWebDriver webDriver, string selector, int maxMilliSecondsWaitTime = 30000)
        {
            CustomWebElement customWebelement = new CustomWebElement(() =>
            {
                return(SeleniumUtils.Wait(() => webDriver.FindElement(By.CssSelector(selector)), selector, maxMilliSecondsWaitTime));
            });

            return(customWebelement);
        }
コード例 #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="element">Elemento - $('#id') ou $('#id')[0]</param>
        /// <param name="isInvertVisible"></param>
        /// <param name="maxMilliSecondsWaitTime"></param>
        public static IWebDriver WaitVisibleByjQueryElement(this IWebDriver webDriver, string element, bool isInvertVisible = false, int maxMilliSecondsWaitTime = 30000)
        {
            SeleniumUtils.WaitCondition(() =>
            {
                string strVisible = webDriver.ExecuteScriptAndReturn($"$({element}).is(':visible');");
                return(string.Compare(strVisible, isInvertVisible ? "false" : "true", true) == 0);
            }, maxMilliSecondsWaitTime);

            return(webDriver);
        }
コード例 #8
0
        /// <summary>
        /// Espera até o retorno de jsReturn == value
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="jsReturn">script q irá retornar um valor</param>
        /// <param name="value">valor a ser comparado</param>
        /// <param name="maxMilliSecondsWaitTime"></param>
        /// <param name="autoConcatReturn">se true coloca de forma automatica a palavra return antes do script</param>
        public static IWebDriver WaitUntil(this IWebDriver webDriver, string jsReturn, Func <string, bool> validateFunction, int maxMilliSecondsWaitTime = 30000, bool autoConcatReturn = true)
        {
            SeleniumUtils.WaitCondition(() =>
            {
                string strValue = webDriver.ExecuteScriptAndReturn(jsReturn, autoConcatReturn);
                return(validateFunction(strValue));
            }, maxMilliSecondsWaitTime);

            return(webDriver);
        }
コード例 #9
0
        /// <summary>
        /// Espera até o retorno de jsReturn == value
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="jsReturn">script q irá retornar um valor</param>
        /// <param name="value">valor a ser comparado</param>
        /// <param name="maxMilliSecondsWaitTime"></param>
        /// <param name="autoConcatReturn">se true coloca de forma automatica a palavra return antes do script</param>
        public static IWebDriver WaitUntil(this IWebDriver webDriver, string jsReturn, string value, int maxMilliSecondsWaitTime = 30000, bool autoConcatReturn = true)
        {
            SeleniumUtils.WaitCondition(() =>
            {
                string strValue = webDriver.ExecuteScriptAndReturn(jsReturn, autoConcatReturn);
                return(string.Compare(strValue, value, true) == 0);
            }, maxMilliSecondsWaitTime);

            return(webDriver);
        }
コード例 #10
0
        /// <summary>
        /// Aguarda até que o elemento esteja visível ou invisível de acordo com seu seletor
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="selector">Seletor</param>
        /// <param name="isInvertVisible">Se true aguarda té que o elemento esteja INVISÍVEL, por padrão ele espera até que esteja VISÍVEL</param>
        /// <param name="maxMilliSecondsWaitTime">Timeout para a esperar o elemento ficar visível/invisível</param>
        private static IWebDriver WaitVisibleBySelectorType(this IWebDriver webDriver, string selector, bool isXPath = false, bool isInvertVisible = false, int maxMilliSecondsWaitTime = 30000)
        {
            SeleniumUtils.WaitCondition(() =>
            {
                string typeFind   = isXPath ? "$x" : "$";
                string strVisible = webDriver.ExecuteScriptAndReturn($"{typeFind}('{selector}').is(':visible');");
                return(string.Compare(strVisible, isInvertVisible ? "false" : "true", true) == 0);
            }, maxMilliSecondsWaitTime);

            return(webDriver);
        }
コード例 #11
0
        /// <summary>
        /// Executa o comando Trigger do jQuery para disparar um evento via Script, se necessário espera um tempo informado antes de disparar o comando
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="selector">Seletor do objeto no qual será acionado o evento</param>
        /// <param name="waitTime">Tempo a ser esperado antes de executar a ação</param>
        /// <param name="triggerEvent">Evento do objeto a ser disparado</param>
        public static void JQueryTriggerBySelector(this IWebDriver webDriver, string selector, int maxMilliSecondsWaitTime = 300, TriggerEvent triggerEvent = TriggerEvent.Click)
        {
            if (maxMilliSecondsWaitTime > 0)
            {
                Thread.Sleep(maxMilliSecondsWaitTime);
            }

            string executeEvent = $"$(\"{selector}\").trigger('{ SeleniumUtils.GetEventName(triggerEvent) }')";

            ((IJavaScriptExecutor)webDriver).ExecuteScript(executeEvent);
        }
コード例 #12
0
        /// <summary>
        /// Busca um elemento em uma lista através de seu seletor e índice, aguardando até que o mesmo seja renderizado com um tiemout de 30 segundos
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="selector"></param>
        /// <param name="indice">Índice do elemento a ser retornado</param>
        /// <param name="maxMilliSecondsWaitTime">Tempo máximo a ser esperado até que o componente tenha sido renderizado</param>
        /// <returns></returns>
        public static ICustomWebElement WaitFindElementsBySelector(this IWebDriver webDriver, string selector, int indice, int maxMilliSecondsWaitTime = 30000)
        {
            CustomWebElement customWebelement = new CustomWebElement(() =>
            {
                return(SeleniumUtils.Wait(() =>
                {
                    var list = webDriver.FindElements(By.CssSelector(selector));

                    if (list.Count < indice)
                    {
                        return null;
                    }
                    else
                    {
                        return list[indice];
                    }
                }, selector, maxMilliSecondsWaitTime));
            });

            return(customWebelement);
        }
コード例 #13
0
 /// <summary>
 /// Busca uma lista de elementos através de um seletor
 /// </summary>
 /// <param name="webDriver"></param>
 /// <param name="selector"></param>
 /// <returns></returns>
 public static ReadOnlyCollection <IWebElement> WaitFindElementsBySelector(this IWebDriver webDriver, string selector, int maxMilliSecondsWaitTime = 30000)
 {
     return(SeleniumUtils.Wait(() => webDriver.FindElements(By.CssSelector(selector)), selector, maxMilliSecondsWaitTime));
 }
コード例 #14
0
        /// <summary>
        /// Espera até o retorno de jsReturn == value
        /// </summary>
        /// <param name="webDriver"></param>
        /// <param name="jsReturn">script q irá retornar um valor</param>
        /// <param name="value">valor a ser comparado</param>
        /// <param name="maxMilliSecondsWaitTime"></param>
        /// <param name="autoConcatReturn">se true coloca de forma automatica a palavra return antes do script</param>
        public static IWebDriver WaitUntil(this IWebDriver webDriver, Func <bool> validateFunction, int maxMilliSecondsWaitTime = 30000, bool autoConcatReturn = true)
        {
            SeleniumUtils.WaitCondition(validateFunction, maxMilliSecondsWaitTime);

            return(webDriver);
        }