Ejemplo n.º 1
0
        internal static Alert SwitchToAlert(RemoteSession session, int timeout)
        {
            string text;

            try {
                text = (string)session.Send(RequestMethod.GET, "/alert_text");
            } catch (Errors.NoAlertPresentError) {
                if (timeout == 0)
                {
                    throw;
                }
                DateTime endTime = session.GetEndTime(timeout);
                while (true)
                {
                    SysWaiter.Wait();
                    try {
                        text = (string)session.SendAgain();
                        break;
                    } catch (Errors.NoAlertPresentError) {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw;
                        }
                    }
                }
            }
            return(new Alert(session, text));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns a web element matching the given method and value
        /// </summary>
        private void WaitAnyElementNotPresent(By byAny, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/element";
            DateTime      endTime = session.GetEndTime(timeout);

            foreach (By by in (By[])byAny.Value)
            {
                if (by == null)
                {
                    break;
                }
                try {
                    string method = By.FormatStrategy(by.Strategy);
                    string value  = by.Value.ToString();
                    session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                    while (true)
                    {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw new Errors.ElementPresentError(byAny);
                        }
                        SysWaiter.Wait();
                        session.SendAgain();
                    }
                } catch (Errors.NoSuchElementError) { }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns a web element matching the given method and value or null if no element found
        /// </summary>
        private WebElement FindFirstElement(Strategy strategy, string value, int timeout)
        {
            RemoteSession session     = this.session;
            string        relativeUri = this.uri + "/element";
            Dictionary    element;

            try {
                string method = By.FormatStrategy(strategy);
                element = (Dictionary)session.Send(RequestMethod.POST, relativeUri, "using", method, "value", value);
            } catch (Errors.NoSuchElementError) {
                if (timeout == 0)
                {
                    throw;
                }
                var endTime = session.GetEndTime(timeout);
                while (true)
                {
                    SysWaiter.Wait();
                    try {
                        element = (Dictionary)session.SendAgain();
                        break;
                    } catch (Errors.NoSuchElementError) {
                        if (DateTime.UtcNow > endTime)
                        {
                            throw;
                        }
                    }
                }
            }
            return(new WebElement(session, element));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Returns a web element matching the given method and value
        /// </summary>
        private void WaitElementNotPresent(Strategy strategy, string value, int timeout)
        {
            RemoteSession session = this.session;
            string        uri     = this.uri + "/element";
            string        method  = By.FormatStrategy(strategy);
            DateTime      endTime = session.GetEndTime(timeout);

            try {
                session.Send(RequestMethod.POST, uri, "using", method, "value", value);
                while (true)
                {
                    SysWaiter.Wait();
                    session.SendAgain();
                    if (DateTime.UtcNow > endTime)
                    {
                        throw new Errors.ElementPresentError(strategy, value);
                    }
                }
            } catch (Errors.NoSuchElementError) { }
        }
Ejemplo n.º 5
0
 internal static Alert SwitchToAlert(RemoteSession session, int timeout) {
     string text;
     try {
         text = (string)session.Send(RequestMethod.GET, "/alert_text");
     } catch (Errors.NoAlertPresentError) {
         if (timeout == 0)
             throw;
         DateTime endTime = session.GetEndTime(timeout);
         while (true) {
             SysWaiter.Wait();
             try {
                 text = (string)session.SendAgain();
                 break;
             } catch (Errors.NoAlertPresentError) {
                 if (DateTime.UtcNow > endTime)
                     throw;
             }
         }
     }
     return new Alert(session, text);
 }