Esempio n. 1
0
        public bool WaitForPageLoad(int firstWait, int timeoutMs, bool needToLog)
        {
            TimerTest PageLoadTimer = new TimerTest();

            Thread.Sleep(firstWait);

            if (timeoutMs < 0)
            {
                throw new Exception("wait time cannot be less than " + firstWait + " ms!");
            }

            for (; PageLoadTimer.GetElapsedTime() < timeoutMs;)
            {
                string readyStateJsStr = "return document.readyState;";

                var javaScriptExecutor = Instance as IJavaScriptExecutor;

                bool isReady = javaScriptExecutor.ExecuteScript(readyStateJsStr).Equals("complete");

                if (isReady)
                {
                    if (needToLog)
                    {
                        PageLoadTimer.Finish("Page Loaded in");
                    }

                    return(true);
                }
            }

            if (needToLog)
            {
                PageLoadTimer.Finish("Page failed to load after");
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        /// Find Web Element.
        /// If element is not ready by Await parameter or absent on the page, it will be seached in period of time configured in paramsLib
        /// </summary>
        /// <param name="by">Configure by what need to search web element</param>
        /// <param name="awaitFor">Await.Visible() or Await.Visible(1000 -- like timeout)</param>
        /// <returns>element wrapper "ElemType"</returns>
        public ElemType Elem(BaseClasses.By by, Await awaitFor)
        {
            TimerTest timer  = new TimerTest();
            ElemType  elType = new ElemType(this);

            if (awaitFor.TimeOut < 0)
            {
                throw new Exception("Wait period cannot be less than 0");
            }

            if (awaitFor.Value == string.Empty)
            {
                elType = FindIfrElement(by);

                if (!elType.IsNull)
                {
                    return(elType);
                }
            }

            for (; timer.GetElapsedTime() < awaitFor.TimeOut;)
            {
                ElemType webElement = FindIfrElement(by);

                if (IsElementReady(webElement, awaitFor))
                {
                    timer.Finish("Element changed status to ready in ");

                    return(webElement);
                }
            }

            timer.Finish("Element wasnt changed it's status to requested in ");

            return(elType);
        }
Esempio n. 3
0
        public bool WaitForAjax(int firstWait, int timeoutMs)
        {
            bool isJqueryComplete    = false;
            bool isPrototypeComplete = false;
            bool isDojoComplete      = false;

            TimerTest timer = new TimerTest();

            Thread.Sleep(firstWait);

            for (; timer.GetElapsedTime() < timeoutMs;)
            {
                try
                {
                    var javaScriptExecutor = Instance as IJavaScriptExecutor;
                    if (javaScriptExecutor != null)
                    {
                        isJqueryComplete = (bool)javaScriptExecutor.ExecuteScript(" return jQuery.active == 0");
                    }
                }
                catch (Exception)
                {
                    //// Normal behaviour
                }

                try
                {
                    var javaScriptExecutor = Instance as IJavaScriptExecutor;
                    if (javaScriptExecutor != null)
                    {
                        isDojoComplete =
                            (bool)
                            javaScriptExecutor.ExecuteScript("userWindow.dojo.io.XMLHTTPTransport.inFlight.length == 0");
                    }
                }
                catch (Exception)
                {
                    //// Normal behaviour
                }

                try
                {
                    var javaScriptExecutor = Instance as IJavaScriptExecutor;
                    if (javaScriptExecutor != null)
                    {
                        isPrototypeComplete =
                            (bool)javaScriptExecutor.ExecuteScript("userWindow.Ajax.activeRequestCount == 0");
                    }
                }
                catch (Exception)
                {
                    //// Normal behaviour
                }

                if (isJqueryComplete | isPrototypeComplete | isDojoComplete)
                {
                    timer.Finish("Wait for Ajax sucessfully finished in");

                    return(true);
                }
            }

            timer.Finish("Wait for Ajax failed after");

            return(false);
        }