當前位置: 首頁>>代碼示例>>C#>>正文


C# Remote.Command類代碼示例

本文整理匯總了C#中OpenQA.Selenium.Remote.Command的典型用法代碼示例。如果您正苦於以下問題:C# Command類的具體用法?C# Command怎麽用?C# Command使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Command類屬於OpenQA.Selenium.Remote命名空間,在下文中一共展示了Command類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Execute

        /// <summary>
        /// Executes a command
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public Response Execute(Command commandToExecute)
        {
            if (commandToExecute == null)
            {
                throw new ArgumentNullException("commandToExecute", "Command to execute cannot be null");
            }

            Response toReturn = null;
            if (commandToExecute.Name == DriverCommand.NewSession)
            {
                this.service.Start();
            }

            // Use a try-catch block to catch exceptions for the Quit
            // command, so that we can get the finally block.
            try
            {
                toReturn = this.internalExecutor.Execute(commandToExecute);
            }
            finally
            {
                if (commandToExecute.Name == DriverCommand.Quit)
                {
                    this.service.Dispose();
                }
            }

            return toReturn;
        }
開發者ID:draculavlad,項目名稱:selenium,代碼行數:34,代碼來源:DriverServiceCommandExecutor.cs

示例2: CreateWebRequest

        /// <summary>
        /// Creates a web request for your command
        /// </summary>
        /// <param name="baseUri">Uri that will have the command run against</param>
        /// <param name="commandToExecute">Command to execute</param>
        /// <returns>A web request of what has been run</returns>
        public HttpWebRequest CreateWebRequest(Uri baseUri, Command commandToExecute)
        {
            HttpWebRequest request = null;
            string[] urlParts = this.resourcePath.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < urlParts.Length; i++)
            {
                string urlPart = urlParts[i];
                if (urlPart.StartsWith("{", StringComparison.OrdinalIgnoreCase) && urlPart.EndsWith("}", StringComparison.OrdinalIgnoreCase))
                {
                    urlParts[i] = GetCommandPropertyValue(urlPart, commandToExecute);
                }
            }

            Uri fullUri;
            string relativeUrl = string.Join("/", urlParts);
            bool uriCreateSucceeded = Uri.TryCreate(baseUri, relativeUrl, out fullUri);
            if (uriCreateSucceeded)
            {
                request = HttpWebRequest.Create(fullUri) as HttpWebRequest;
                request.Method = this.method;
            }
            else
            {
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to create URI from base {0} and relative path {1}", baseUri == null ? string.Empty : baseUri.ToString(), relativeUrl));
            }

            return request;
        }
開發者ID:JacquesBonet,項目名稱:selenium-1,代碼行數:34,代碼來源:CommandInfo.cs

示例3: Execute

        public Response Execute(Command commandToExecute)
        {
            Response result = null;
            if (commandToExecute.Name == DriverCommand.NewSession && this.Service != null)
            {
                this.Service.Start();
            }

            try
            {
                result = RealExecutor.Execute(commandToExecute);
                return result;
            }
            catch (Exception e)
            {
                if ((commandToExecute.Name == DriverCommand.NewSession) && (this.Service != null))
                {
                    this.Service.Dispose();
                }
                throw e;
            }
            finally
            {
                if (result != null && result.Status != WebDriverResult.Success &&
                    commandToExecute.Name == DriverCommand.NewSession && this.Service != null)
                {
                    this.Service.Dispose();
                }

                if (commandToExecute.Name == DriverCommand.Quit && this.Service != null)
                {
                    this.Service.Dispose();
                }
            }
        }
開發者ID:trbnb,項目名稱:appium-dotnet-driver,代碼行數:35,代碼來源:AppiumCommandExecutor.cs

示例4: Send

 /// <summary>
 /// Sends a command to the SafariDriver and waits for a response.
 /// </summary>
 /// <param name="command">The <see cref="Command"/> to send to the driver.</param>
 /// <returns>The <see cref="Response"/> from the command.</returns>
 public Response Send(Command command)
 {
     SafariCommand wrappedCommand = new SafariCommand(command);
     this.commandQueue.Enqueue(wrappedCommand);
     string commandJson = JsonConvert.SerializeObject(wrappedCommand);
     this.connection.Send(commandJson);
     return this.WaitForResponse(TimeSpan.FromSeconds(30));
 }
開發者ID:jamesoram,項目名稱:Selenium2,代碼行數:13,代碼來源:SafariDriverConnection.cs

示例5: ExtractParameters

        private static Dictionary<string, object> ExtractParameters(Command command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command", "command must not be null");
            }

            return command.Parameters;
        }
開發者ID:Rameshnathan,項目名稱:selenium,代碼行數:9,代碼來源:SafariCommand.cs

示例6: ExtractName

        private static string ExtractName(Command command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command", "command must not be null");
            }

            return command.Name;
        }
開發者ID:Rameshnathan,項目名稱:selenium,代碼行數:9,代碼來源:SafariCommand.cs

示例7: ExtractSessionId

        private static SessionId ExtractSessionId(Command command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command", "command must not be null");
            }

            return command.SessionId;
        }
開發者ID:Rameshnathan,項目名稱:selenium,代碼行數:9,代碼來源:SafariCommand.cs

示例8: ForwardCommand

        public string ForwardCommand(Command commandToForward, bool verbose = true, int timeout = 0)
        {
            var serializedCommand = JsonConvert.SerializeObject(commandToForward);

            var response = this.SendRequest(serializedCommand, verbose, timeout);
            if (response.Key == HttpStatusCode.OK)
            {
                return response.Value;
            }

            throw new InnerDriverRequestException(response.Value, response.Key);
        }
開發者ID:2gis,項目名稱:winphonedriver,代碼行數:12,代碼來源:Requester.cs

示例9: Execute

        /// <summary>
        /// Executes a command
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public Response Execute(Command commandToExecute)
        {
            CommandInfo info = CommandInfoRepository.Instance.GetCommandInfo(commandToExecute.Name);
            HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute);
            request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds;
            request.Accept = RequestAcceptHeader;
            if (request.Method == CommandInfo.PostCommand)
            {
                string payload = commandToExecute.ParametersAsJsonString;
                byte[] data = Encoding.UTF8.GetBytes(payload);
                request.ContentType = JsonMimeType;
                System.IO.Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }

            return CreateResponse(request);
        }
開發者ID:v4viveksharma90,項目名稱:selenium,代碼行數:23,代碼來源:HttpCommandExecutor.cs

示例10: DoImpl

        protected override string DoImpl()
        {
            // It is easier to reparse desired capabilities as JSON instead of re-mapping keys to attributes and calling type conversions, 
            // so we will take possible one time performance hit by serializing Dictionary and deserializing it as Capabilities object
            var serializedCapability =
                JsonConvert.SerializeObject(this.ExecutedCommand.Parameters["desiredCapabilities"]);
            this.Automator.ActualCapabilities = Capabilities.CapabilitiesFromJsonString(serializedCapability);

            var innerIp = this.InitializeApplication(this.Automator.ActualCapabilities.DebugConnectToRunningApp);

            this.Automator.CommandForwarder = new Requester(innerIp, this.Automator.ActualCapabilities.InnerPort);

            long timeout = this.Automator.ActualCapabilities.LaunchTimeout;

            const int PingStep = 500;
            var stopWatch = new Stopwatch();
            while (timeout > 0)
            {
                stopWatch.Restart();

                Logger.Trace("Ping inner driver");
                var pingCommand = new Command(null, "ping", null);
                var responseBody = this.Automator.CommandForwarder.ForwardCommand(pingCommand, false, 2000);
                if (responseBody.StartsWith("<pong>", StringComparison.Ordinal))
                {
                    break;
                }

                Thread.Sleep(PingStep);
                stopWatch.Stop();
                timeout -= stopWatch.ElapsedMilliseconds;
            }

            // TODO throw AutomationException with SessionNotCreatedException if timeout and uninstall the app
            Console.WriteLine();

            // Gives sometime to load visuals (needed only in case of slow emulation)
            Thread.Sleep(this.Automator.ActualCapabilities.LaunchDelay);

            var jsonResponse = this.JsonResponse(ResponseStatus.Success, this.Automator.ActualCapabilities);

            return jsonResponse;
        }
開發者ID:sleekweasel,項目名稱:winphonedriver,代碼行數:43,代碼來源:NewSessionExecutor.cs

示例11: Execute

        /// <summary>
        /// Executes a command
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public Response Execute(Command commandToExecute)
        {
            CommandInfo info = CommandInfoRepository.Instance.GetCommandInfo(commandToExecute.Name);
            HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
            HttpWebRequest request = info.CreateWebRequest(remoteServerUri, commandToExecute);
            request.Timeout = 15000;
            request.Accept = "application/json, image/png";
            if (request.Method == CommandInfo.PostCommand)
            {
                string payload = commandToExecute.ParametersAsJsonString;
                byte[] data = Encoding.UTF8.GetBytes(payload);
                request.ContentType = "application/json";
                System.IO.Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }

            return CreateResponse(request);
        }
開發者ID:promo888,項目名稱:selenium,代碼行數:24,代碼來源:HttpCommandExecutor.cs

示例12: Execute

        /// <summary>
        /// Executes a command
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public Response Execute(Command commandToExecute)
        {
            CommandInfo info = commandDictionary[commandToExecute.Name];
            HttpWebRequest.DefaultMaximumErrorResponseLength = -1;
            HttpWebRequest request = info.CreateWebRequest(remoteServerUri, commandToExecute);
            request.Accept = "application/json, image/png";
            string payload = JsonConvert.SerializeObject(commandToExecute.Parameters, new JsonConverter[] { new PlatformJsonConverter(), new CookieJsonConverter(), new CharArrayJsonConverter() });
            if (request.Method == CommandInfo.PostCommand)
            {
                byte[] data = Encoding.UTF8.GetBytes(payload);
                request.ContentType = "application/json";
                request.KeepAlive = false;
                System.IO.Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }

            return CreateResponse(request);
        }
開發者ID:epall,項目名稱:selenium,代碼行數:24,代碼來源:HttpCommandExecutor.cs

示例13: ConnectToApp

        private void ConnectToApp()
        {
            long timeout = this.Automator.ActualCapabilities.LaunchTimeout;

            const int PingStep = 500;
            var stopWatch = new Stopwatch();
            while (timeout > 0)
            {
                stopWatch.Restart();

                Logger.Trace("Ping inner driver");
                var pingCommand = new Command(null, "ping", null);
                var responseBody = this.Automator.CommandForwarder.ForwardCommand(pingCommand, false, 2000);
                if (responseBody.StartsWith("<pong>", StringComparison.Ordinal))
                {
                    break;
                }

                Thread.Sleep(PingStep);
                stopWatch.Stop();
                timeout -= stopWatch.ElapsedMilliseconds;
            }
        }
開發者ID:2gis,項目名稱:winphonedriver,代碼行數:23,代碼來源:NewSessionExecutor.cs

示例14: Execute

        public Response Execute(Command commandToExecute)
        {
            if (commandToExecute == null)
            {
                throw new ArgumentNullException("commandToExecute", "Command may not be null");
            }

            if (commandToExecute.Name == DriverCommand.NewSession)
            {
                this.service.Start();
            }

            try
            {
                return this.internalExecutor.Execute(commandToExecute);
            }
            finally
            {
                if (commandToExecute.Name == DriverCommand.Quit)
                {
                    this.service.Dispose();
                }
            }
        }
開發者ID:Th3RD,項目名稱:Winium,代碼行數:24,代碼來源:WiniumDriverCommandExecutor.cs

示例15: Execute

        /// <summary>
        /// Executes a command with the ChromeDriver.
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public override Response Execute(Command commandToExecute)
        {
            Response toReturn = null;
            if (commandToExecute.Name == DriverCommand.NewSession)
            {
                this.service.Start();
            }

            // Use a try-catch block to catch exceptions for the Quit
            // command, so that we can get the finally block.
            try
            {
                toReturn = base.Execute(commandToExecute);
            }
            finally
            {
                if (commandToExecute.Name == DriverCommand.Quit)
                {
                    this.service.Dispose();
                }
            }

            return toReturn;
        }
開發者ID:kaushik9k,項目名稱:Selenium2,代碼行數:29,代碼來源:ChromeCommandExecutor.cs


注:本文中的OpenQA.Selenium.Remote.Command類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。