当前位置: 首页>>代码示例>>C#>>正文


C# Remote.Response类代码示例

本文整理汇总了C#中OpenQA.Selenium.Remote.Response的典型用法代码示例。如果您正苦于以下问题:C# Response类的具体用法?C# Response怎么用?C# Response使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Response类属于OpenQA.Selenium.Remote命名空间,在下文中一共展示了Response类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateRemoteWebElementFromResponse

        protected RemoteWebElement CreateRemoteWebElementFromResponse(Response response)
        {
            var elementDictionary = response.Value as Dictionary<string, object>;
            if (elementDictionary == null)
            {
                return null;
            }

            return new RemoteWebElement((RemoteWebDriver)this.WrappedDriver, (string)elementDictionary["ELEMENT"]);
        }
开发者ID:2gis,项目名称:Winium.Elements,代码行数:10,代码来源:DesktopElement.cs

示例2: WaitForResponse

        private Response WaitForResponse(TimeSpan timeout)
        {
            bool timedOut = false;
            Response response = null;
            DateTime endTime = DateTime.Now.Add(timeout);
            while (response == null && !timedOut)
            {
                if (this.connectionClosed)
                {
                    response = new Response();
                    break;
                }
                else
                {
                    response = this.GetQueuedResponse();
                    if (response != null)
                    {
                        if (response.Value is string)
                        {
                            // First, collapse all \r\n pairs to \n, then replace all \n with
                            // System.Environment.NewLine. This ensures the consistency of
                            // the values.
                            response.Value = ((string)response.Value).Replace("\r\n", "\n").Replace("\n", System.Environment.NewLine);
                        }

                        break;
                    }
                }

                Thread.Sleep(250);
                if (DateTime.Now > endTime)
                {
                    timedOut = true;
                }
            }

            if (timedOut)
            {
                Dictionary<string, object> valueDictionary = new Dictionary<string, object>();
                valueDictionary["message"] = "Timed out waiting for response from WebSocket server";
                response = new Response();
                response.Status = WebDriverResult.Timeout;
                response.Value = valueDictionary;
            }

            return response;
        }
开发者ID:RanchoLi,项目名称:selenium,代码行数:47,代码来源:SafariDriverConnection.cs

示例3: InternalExecute

        internal Response InternalExecute(string driverCommandToExecute, Dictionary<string, object> parameters)
        {
            //return this.Execute(driverCommandToExecute, parameters);

            Response resp =
                new Response();

            if ("getElementTagName" == driverCommandToExecute) {
                resp.Value = this.TagNameResponse;
            }
            if ("getElementText" == driverCommandToExecute) {
                resp.Value = this.TextResponse;
            }
            if ("isElementEnabled" == driverCommandToExecute) {
                resp.Value = this.EnabledResponse;
            }
            if ("isElementSelected" == driverCommandToExecute) {
                resp.Value = this.SelectedResponse;
            }
            if ("isElementDisplayed" == driverCommandToExecute) {
                resp.Value = this.DisplayedResponse;
            }
            //        	if ("" == driverCommandToExecute) {
            //
            //        	}
            //        	if ("" == driverCommandToExecute) {
            //
            //        	}
            //        	if ("" == driverCommandToExecute) {
            //
            //        	}
            //        	if ("" == driverCommandToExecute) {
            //
            //        	}
            //        	if ("" == driverCommandToExecute) {
            //
            //        	}

            return resp;
        }
开发者ID:krisdages,项目名称:STUPS,代码行数:40,代码来源:FakeRemoteWebDriver.cs

示例4: WaitForResponse

        private Response WaitForResponse(TimeSpan timeout)
        {
            bool timedOut = false;
            Response response = null;
            DateTime endTime = DateTime.Now.Add(timeout);
            while (response == null && !timedOut)
            {
                if (this.connectionClosed)
                {
                    response = new Response();
                    break;
                }
                else
                {
                    response = this.GetQueuedResponse();
                    if (response != null)
                    {
                        break;
                    }
                }

                Thread.Sleep(250);
                if (DateTime.Now > endTime)
                {
                    timedOut = true;
                }
            }

            if (timedOut)
            {
                Dictionary<string, object> valueDictionary = new Dictionary<string, object>();
                valueDictionary["message"] = "Timed out waiting for response from WebSocket server";
                response = new Response();
                response.Status = WebDriverResult.Timeout;
                response.Value = valueDictionary;
            }

            return response;
        }
开发者ID:kaushik9k,项目名称:Selenium2,代码行数:39,代码来源:SafariDriverConnection.cs

示例5: GetElementFromResponse

        /// <summary>
        /// Find the element in the response
        /// </summary>
        /// <param name="response">Response from the browser</param>
        /// <returns>Element from the page</returns>
        internal IWebElement GetElementFromResponse(Response response)
        {
            if (response == null)
            {
                throw new NoSuchElementException();
            }

            RemoteWebElement element = null;
            Dictionary<string, object> elementDictionary = response.Value as Dictionary<string, object>;
            if (elementDictionary != null)
            {
                // TODO: Remove this "if" logic once the spec is properly updated
                // and remote-end implementations comply.
                string id = string.Empty;
                if (elementDictionary.ContainsKey("element-6066-11e4-a52e-4f735466cecf"))
                {
                    id = (string)elementDictionary["element-6066-11e4-a52e-4f735466cecf"];
                }
                else if (elementDictionary.ContainsKey("ELEMENT"))
                {
                    id = (string)elementDictionary["ELEMENT"];
                }

                element = this.CreateElement(id);
            }

            return element;
        }
开发者ID:DawidJanczak,项目名称:selenium,代码行数:33,代码来源:RemoteWebDriver.cs

示例6: UnpackAndThrowOnError

        private static void UnpackAndThrowOnError(Response errorResponse)
        {
            // Check the status code of the error, and only handle if not success.
            if (errorResponse.Status != WebDriverResult.Success)
            {
                Dictionary<string, object> errorAsDictionary = errorResponse.Value as Dictionary<string, object>;
                if (errorAsDictionary != null)
                {
                    ErrorResponse errorResponseObject = new ErrorResponse(errorAsDictionary);
                    string errorMessage = errorResponseObject.Message;
                    switch (errorResponse.Status)
                    {
                        case WebDriverResult.NoSuchElement:
                            throw new NoSuchElementException(errorMessage);

                        case WebDriverResult.NoSuchFrame:
                            throw new NoSuchFrameException(errorMessage);

                        case WebDriverResult.UnknownCommand:
                            throw new NotImplementedException(errorMessage);

                        case WebDriverResult.ObsoleteElement:
                            throw new StaleElementReferenceException(errorMessage);

                        case WebDriverResult.ElementNotDisplayed:
                            throw new ElementNotVisibleException(errorMessage);

                        case WebDriverResult.InvalidElementState:
                        case WebDriverResult.ElementNotSelectable:
                            throw new InvalidElementStateException(errorMessage);

                        case WebDriverResult.UnhandledError:
                            throw new InvalidOperationException(errorMessage);

                        case WebDriverResult.NoSuchDocument:
                            throw new NoSuchElementException(errorMessage);

                        case WebDriverResult.Timeout:
                            throw new WebDriverTimeoutException(errorMessage);

                        case WebDriverResult.NoSuchWindow:
                            throw new NoSuchWindowException(errorMessage);

                        case WebDriverResult.InvalidCookieDomain:
                        case WebDriverResult.UnableToSetCookie:
                            throw new WebDriverException(errorMessage);

                        case WebDriverResult.AsyncScriptTimeout:
                            throw new WebDriverTimeoutException(errorMessage);

                        case WebDriverResult.UnexpectedAlertOpen:
                            // TODO(JimEvans): Handle the case where the unexpected alert setting
                            // has been set to "ignore", so there is still a valid alert to be
                            // handled.
                            string alertText = string.Empty;
                            if (errorAsDictionary.ContainsKey("alert"))
                            {
                                Dictionary<string, object> alertDescription = errorAsDictionary["alert"] as Dictionary<string, object>;
                                if (alertDescription != null && alertDescription.ContainsKey("text"))
                                {
                                    alertText = alertDescription["text"].ToString();
                                }
                            }

                            throw new UnhandledAlertException(errorMessage, alertText);

                        case WebDriverResult.NoAlertPresent:
                            throw new NoAlertPresentException(errorMessage);

                        case WebDriverResult.InvalidSelector:
                            throw new InvalidSelectorException(errorMessage);

                        default:
                            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", errorMessage, errorResponse.Status));
                    }
                }
                else
                {
                    throw new WebDriverException("Unexpected error. " + errorResponse.Value.ToString());
                }
            }
        }
开发者ID:DawidJanczak,项目名称:selenium,代码行数:82,代码来源:RemoteWebDriver.cs

示例7: Execute

        /// <summary>
        /// Executes a command with this driver .
        /// </summary>
        /// <param name="driverCommandToExecute">A <see cref="DriverCommand"/> value representing the command to execute.</param>
        /// <param name="parameters">A <see cref="Dictionary{K, V}"/> containing the names and values of the parameters of the command.</param>
        /// <returns>A <see cref="Response"/> containing information about the success or failure of the command and any data returned by the command.</returns>
        protected virtual Response Execute(string driverCommandToExecute, Dictionary<string, object> parameters)
        {
            Command commandToExecute = new Command(this.sessionId, driverCommandToExecute, parameters);

            Response commandResponse = new Response();

            try
            {
                commandResponse = this.executor.Execute(commandToExecute);
            }
            catch (System.Net.WebException e)
            {
                commandResponse.Status = WebDriverResult.UnhandledError;
                commandResponse.Value = e;
            }

            if (commandResponse.Status != WebDriverResult.Success)
            {
                UnpackAndThrowOnError(commandResponse);
            }

            return commandResponse;
        }
开发者ID:DawidJanczak,项目名称:selenium,代码行数:29,代码来源:RemoteWebDriver.cs

示例8: GetElementFromResponse

        /// <summary>
        /// Find the element in the response
        /// </summary>
        /// <param name="response">Reponse from the browser</param>
        /// <returns>Element from the page</returns>
        internal IWebElement GetElementFromResponse(Response response)
        {
            IWebElement element = null;
            ReadOnlyCollection<IWebElement> elements = GetElementsFromResponse(response);
            if (elements.Count > 0)
            {
                element = elements[0];
            }

            return element;
        }
开发者ID:epall,项目名称:selenium,代码行数:16,代码来源:RemoteWebDriver.cs

示例9: GetElementsFromResponse

        /// <summary>
        /// Finds the elements that are in the response
        /// </summary>
        /// <param name="response">Response from the browser</param>
        /// <returns>Collection of elements</returns>
        internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response response)
        {
            List<IWebElement> toReturn = new List<IWebElement>();
            object[] elements = response.Value as object[];
            foreach (object elementObject in elements)
            {
                Dictionary<string, object> elementDictionary = elementObject as Dictionary<string, object>;
                if (elementDictionary != null)
                {
                    string id = (string)elementDictionary["ELEMENT"];
                    RemoteWebElement element = this.CreateElement(id);
                    toReturn.Add(element);
                }
            }

            return toReturn.AsReadOnly();
        }
开发者ID:hpandey34,项目名称:selenium,代码行数:22,代码来源:RemoteWebDriver.cs

示例10: GetElementFromResponse

        /// <summary>
        /// Find the element in the response
        /// </summary>
        /// <param name="response">Response from the browser</param>
        /// <returns>Element from the page</returns>
        internal IWebElement GetElementFromResponse(Response response)
        {
            if (response == null)
            {
                throw new NoSuchElementException();
            }

            RemoteWebElement element = null;
            Dictionary<string, object> elementDictionary = response.Value as Dictionary<string, object>;
            if (elementDictionary != null)
            {
                string id = (string)elementDictionary["ELEMENT"];
                element = this.CreateElement(id);
            }

            return element;
        }
开发者ID:hpandey34,项目名称:selenium,代码行数:22,代码来源:RemoteWebDriver.cs

示例11: UnpackAndThrowOnError

        private static void UnpackAndThrowOnError(Response errorResponse)
        {
            // Check the status code of the error, and only handle if not success.
            if (errorResponse.Status != WebDriverResult.Success)
            {
                Dictionary<string, object> errorAsDictionary = errorResponse.Value as Dictionary<string, object>;
                if (errorAsDictionary != null)
                {
                    ErrorResponse errorResponseObject = new ErrorResponse(errorAsDictionary);
                    string errorMessage = errorResponseObject.Message;
                    switch (errorResponse.Status)
                    {
                        case WebDriverResult.NoSuchElement:
                            throw new NoSuchElementException(errorMessage);

                        case WebDriverResult.NoSuchFrame:
                            throw new NoSuchFrameException(errorMessage);

                        case WebDriverResult.UnknownCommand:
                            throw new NotImplementedException(errorMessage);

                        case WebDriverResult.ObsoleteElement:
                            throw new StaleElementReferenceException(errorMessage);

                        case WebDriverResult.ElementNotDisplayed:
                            throw new ElementNotVisibleException(errorMessage);

                        case WebDriverResult.InvalidElementState:
                        case WebDriverResult.ElementNotSelectable:
                            throw new InvalidElementStateException(errorMessage);

                        case WebDriverResult.UnhandledError:
                            throw new InvalidOperationException(errorMessage);

                        case WebDriverResult.NoSuchDocument:
                            throw new NoSuchElementException(errorMessage);

                        case WebDriverResult.Timeout:
                            throw new TimeoutException("The driver reported that the command timed out. There may "
                                                       + "be several reasons for this. Check that the destination "
                                                       + "site is in IE's 'Trusted Sites' (accessed from Tools->"
                                                       + "Internet Options in the 'Security' tab) If it is a "
                                                       + "trusted site, then the request may have taken more than "
                                                       + "a minute to finish.");

                        case WebDriverResult.NoSuchWindow:
                            throw new NoSuchWindowException(errorMessage);

                        case WebDriverResult.InvalidCookieDomain:
                        case WebDriverResult.UnableToSetCookie:
                            throw new WebDriverException(errorMessage);

                        case WebDriverResult.AsyncScriptTimeout:
                            throw new TimeoutException(errorMessage);

                        case WebDriverResult.NoAlertPresent:
                            throw new NoAlertPresentException(errorMessage);

                        case WebDriverResult.InvalidSelector:
                            throw new InvalidSelectorException(errorMessage);

                        default:
                            throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "{0} ({1})", errorMessage, errorResponse.Status));
                    }
                }
                else
                {
                    throw new WebDriverException("Unexpected error. " + errorResponse.Value.ToString());
                }
            }
        }
开发者ID:Goldcap,项目名称:Constellation,代码行数:71,代码来源:RemoteWebDriver.cs

示例12: Execute

        /// <summary>
        /// Executes commands with the driver 
        /// </summary>
        /// <param name="driverCommandToExecute">Command that needs executing</param>
        /// <param name="parameters">Parameters needed for the command</param>
        /// <returns>WebDriver Response</returns>
        internal Response Execute(DriverCommand driverCommandToExecute, object[] parameters)
        {
            Command commandToExecute = new Command(sessionId, new Context("foo"), driverCommandToExecute, parameters);

            Response commandResponse = new Response();

            try
            {
                commandResponse = executor.Execute(commandToExecute);
                AmendElementValueIfNecessary(commandResponse);
            }
            catch (System.Net.WebException e)
            {
                commandResponse.IsError = true;
                commandResponse.Value = e;
            }

            if (commandResponse.IsError)
            {
                UnpackAndThrowOnError(commandResponse.Value);
            }

            return commandResponse;
        }
开发者ID:epall,项目名称:selenium,代码行数:30,代码来源:RemoteWebDriver.cs

示例13: GetElementsFromResponse

        /// <summary>
        /// Finds the elements that are in the response
        /// </summary>
        /// <param name="response">Response from the browser</param>
        /// <returns>Collection of elements</returns>
        internal ReadOnlyCollection<IWebElement> GetElementsFromResponse(Response response)
        {
            List<IWebElement> toReturn = new List<IWebElement>();
            object[] elements = response.Value as object[];
            foreach (object elementObject in elements)
            {
                Dictionary<string, object> elementDictionary = elementObject as Dictionary<string, object>;
                if (elementDictionary != null)
                {
                    // TODO: Remove this "if" logic once the spec is properly updated
                    // and remote-end implementations comply.
                    string id = string.Empty;
                    if (elementDictionary.ContainsKey("element-6066-11e4-a52e-4f735466cecf"))
                    {
                        id = (string)elementDictionary["element-6066-11e4-a52e-4f735466cecf"];
                    }
                    else if (elementDictionary.ContainsKey("ELEMENT"))
                    {
                        id = (string)elementDictionary["ELEMENT"];
                    }

                    RemoteWebElement element = this.CreateElement(id);
                    toReturn.Add(element);
                }
            }

            return toReturn.AsReadOnly();
        }
开发者ID:DawidJanczak,项目名称:selenium,代码行数:33,代码来源:RemoteWebDriver.cs

示例14: FromJson

 /// <summary>
 /// Returns a new <see cref="Response"/> from a JSON-encoded string.
 /// </summary>
 /// <param name="value">The JSON string to deserialize into a <see cref="Response"/>.</param>
 /// <returns>A <see cref="Response"/> object described by the JSON string.</returns>
 public static Response FromJson(string value)
 {
     Dictionary<string, object> deserializedResponse = JsonConvert.DeserializeObject<Dictionary<string, object>>(value, new ResponseValueJsonConverter());
     Response response = new Response(deserializedResponse);
     return response;
 }
开发者ID:koolo90,项目名称:selenium,代码行数:11,代码来源:Response.cs

示例15: GetElementsFrom

        /// <summary>
        /// Gets the elements from the response coming back from Chrome
        /// </summary>
        /// <param name="response">The Chrome Response</param>
        /// <returns>A readonlycollection of WebElement</returns>
        public ReadOnlyCollection<IWebElement> GetElementsFrom(Response response)
        {
            List<IWebElement> elements = new List<IWebElement>();
            object[] result = response.Value as object[];
            if (result != null)
            {
                foreach (object element in result)
                {
                    elements.Add(new ChromeWebElement(this, (string)element));
                }
            }

            return new ReadOnlyCollection<IWebElement>(elements);
        }
开发者ID:epall,项目名称:selenium,代码行数:19,代码来源:ChromeDriver.cs


注:本文中的OpenQA.Selenium.Remote.Response类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。