Holds the information about all commands specified by the JSON wire protocol. This class cannot be inherited, as it is intended to be a singleton, and allowing subclasses introduces the possibility of multiple instances.
예제 #1
0
        /// <summary>
        /// Executes a command
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public virtual Response Execute(Command commandToExecute)
        {
            if (commandToExecute == null)
            {
                throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null");
            }

            CommandInfo info = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name);

            if (info == null)
            {
                throw new NotImplementedException(string.Format("The command you are attempting to execute, {0}, does not exist in the protocol dialect used by the remote end.", commandToExecute.Name));
            }

            HttpRequestInfo  requestInfo  = new HttpRequestInfo(this.remoteServerUri, commandToExecute, info);
            HttpResponseInfo responseInfo = this.MakeHttpRequest(requestInfo);

            Response toReturn = this.CreateResponse(responseInfo);

            if (commandToExecute.Name == DriverCommand.NewSession && toReturn.IsSpecificationCompliant)
            {
                // If we are creating a new session, sniff the response to determine
                // what protocol level we are using. If the response contains a
                // field called "status", it's not a spec-compliant response.
                // Each response is polled for this, and sets a property describing
                // whether it's using the W3C protocol dialect.
                // TODO(jimevans): Reverse this test to make it the default path when
                // most remote ends speak W3C, then remove it entirely when legacy
                // protocol is phased out.
                this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository();
            }

            return(toReturn);
        }
        public virtual Response Execute(Command commandToExecute)
        {
            if (commandToExecute == null)
            {
                throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null");
            }
            CommandInfo    commandInfo    = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name);
            HttpWebRequest httpWebRequest = commandInfo.CreateWebRequest(this.remoteServerUri, commandToExecute);

            httpWebRequest.Timeout   = (int)this.serverResponseTimeout.TotalMilliseconds;
            httpWebRequest.Accept    = "application/json, image/png";
            httpWebRequest.KeepAlive = this.enableKeepAlive;
            httpWebRequest.ServicePoint.ConnectionLimit = 2000;
            if (httpWebRequest.Method == "POST")
            {
                string parametersAsJsonString = commandToExecute.ParametersAsJsonString;
                byte[] bytes = Encoding.UTF8.GetBytes(parametersAsJsonString);
                httpWebRequest.ContentType = "application/json;charset=utf-8";
                Stream requestStream = httpWebRequest.GetRequestStream();
                requestStream.Write(bytes, 0, bytes.Length);
                requestStream.Close();
            }
            Response response = this.CreateResponse(httpWebRequest);

            if (commandToExecute.Name == DriverCommand.NewSession && response.IsSpecificationCompliant)
            {
                this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository();
            }
            return(response);
        }
예제 #3
0
        /// <summary>
        /// Executes a command
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public virtual Response Execute(Command commandToExecute)
        {
            if (commandToExecute == null)
            {
                throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null");
            }

            CommandInfo    info    = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name);
            HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute);

            request.Timeout   = (int)this.serverResponseTimeout.TotalMilliseconds;
            request.Accept    = RequestAcceptHeader;
            request.KeepAlive = this.enableKeepAlive;
            request.ServicePoint.ConnectionLimit = 2000;
            if (request.Method == CommandInfo.PostCommand)
            {
                string payload = commandToExecute.ParametersAsJsonString;
                byte[] data    = Encoding.UTF8.GetBytes(payload);
                request.ContentType = ContentTypeHeader;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }

            Response toReturn = this.CreateResponse(request);

            if (commandToExecute.Name == DriverCommand.NewSession)
            {
                // If we are creating a new session, sniff the response to determine
                // what protocol level we are using. If the response contains a
                // capability called "specificationLevel" that's an integer value
                // and that's greater than 0, that means we're using the W3C protocol
                // dialect.
                // TODO(jimevans): Reverse this test to make it the default path when
                // most remote ends speak W3C, then remove it entirely when legacy
                // protocol is phased out.
                Dictionary <string, object> capabilities = toReturn.Value as Dictionary <string, object>;
                if (capabilities != null)
                {
                    if (capabilities.ContainsKey("specificationLevel"))
                    {
                        int returnedSpecLevel = Convert.ToInt32(capabilities["specificationLevel"]);
                        if (returnedSpecLevel > 0)
                        {
                            this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository();
                        }
                    }
                }
            }

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

            CommandInfo    info    = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name);
            HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute);

            request.Timeout   = (int)this.serverResponseTimeout.TotalMilliseconds;
            request.Accept    = RequestAcceptHeader;
            request.KeepAlive = this.enableKeepAlive;
            request.ServicePoint.ConnectionLimit = 2000;
            if (request.Method == CommandInfo.PostCommand)
            {
                string payload = commandToExecute.ParametersAsJsonString;
                byte[] data    = Encoding.UTF8.GetBytes(payload);
                request.ContentType = ContentTypeHeader;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }

            Response toReturn = this.CreateResponse(request);

            if (commandToExecute.Name == DriverCommand.NewSession && toReturn.IsSpecificationCompliant)
            {
                // If we are creating a new session, sniff the response to determine
                // what protocol level we are using. If the response contains a
                // field called "status", it's not a spec-compliant response.
                // Each response is polled for this, and sets a property describing
                // whether it's using the W3C protocol dialect.
                // TODO(jimevans): Reverse this test to make it the default path when
                // most remote ends speak W3C, then remove it entirely when legacy
                // protocol is phased out.
                this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository();
            }

            return(toReturn);
        }
 /// <summary>
 /// This method adds Appium-specific commands to the given 
 /// CommandInfoRepository
 /// </summary>
 /// <param name="repo">is a CommandInfoRepository instance which is used</param>
 /// <returns>The given CommandInfoRepository instance with added Appium-specific commands</returns>
 internal static CommandInfoRepository Merge(CommandInfoRepository repo)
 {
     foreach (AppiumCommand entry in CommandList)
     {
         var commandInfo = new CommandInfo(entry.CommandType, entry.ApiEndpoint);
         repo.TryAddCommand(entry.CommandName, commandInfo);
     }
     return repo;
 }
예제 #6
0
        /// <summary>
        /// Executes a command
        /// </summary>
        /// <param name="commandToExecute">The command you wish to execute</param>
        /// <returns>A response from the browser</returns>
        public virtual Response Execute(Command commandToExecute)
        {
            if (commandToExecute == null)
            {
                throw new ArgumentNullException("commandToExecute", "commandToExecute cannot be null");
            }

            CommandInfo info = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name);
            HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute);
            request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds;
            request.Accept = RequestAcceptHeader;
            request.KeepAlive = this.enableKeepAlive;
            request.ServicePoint.ConnectionLimit = 2000;
            if (request.Method == CommandInfo.PostCommand)
            {
                string payload = commandToExecute.ParametersAsJsonString;
                byte[] data = Encoding.UTF8.GetBytes(payload);
                request.ContentType = ContentTypeHeader;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }

            Response toReturn = this.CreateResponse(request);
            if (commandToExecute.Name == DriverCommand.NewSession)
            {
                // If we are creating a new session, sniff the response to determine
                // what protocol level we are using. If the response contains a
                // capability called "specificationLevel" that's an integer value
                // and that's greater than 0, that means we're using the W3C protocol
                // dialect.
                // TODO(jimevans): Reverse this test to make it the default path when
                // most remote ends speak W3C, then remove it entirely when legacy
                // protocol is phased out.
                Dictionary<string, object> capabilities = toReturn.Value as Dictionary<string, object>;
                if (capabilities != null)
                {
                    if (capabilities.ContainsKey("specificationLevel"))
                    {
                        int returnedSpecLevel = Convert.ToInt32(capabilities["specificationLevel"]);
                        if (returnedSpecLevel > 0)
                        {
                            this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository();
                        }
                    }
                }
            }

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

            CommandInfo info = this.commandInfoRepository.GetCommandInfo(commandToExecute.Name);
            HttpWebRequest request = info.CreateWebRequest(this.remoteServerUri, commandToExecute);
            request.Timeout = (int)this.serverResponseTimeout.TotalMilliseconds;
            request.Accept = RequestAcceptHeader;
            request.KeepAlive = this.enableKeepAlive;
            request.ServicePoint.ConnectionLimit = 2000;
            if (request.Method == CommandInfo.PostCommand)
            {
                string payload = commandToExecute.ParametersAsJsonString;
                byte[] data = Encoding.UTF8.GetBytes(payload);
                request.ContentType = ContentTypeHeader;
                Stream requestStream = request.GetRequestStream();
                requestStream.Write(data, 0, data.Length);
                requestStream.Close();
            }

            Response toReturn = this.CreateResponse(request);
            if (commandToExecute.Name == DriverCommand.NewSession && toReturn.IsSpecificationCompliant)
            {
                // If we are creating a new session, sniff the response to determine
                // what protocol level we are using. If the response contains a
                // field called "status", it's not a spec-compliant response.
                // Each response is polled for this, and sets a property describing
                // whether it's using the W3C protocol dialect.
                // TODO(jimevans): Reverse this test to make it the default path when
                // most remote ends speak W3C, then remove it entirely when legacy
                // protocol is phased out.
                this.commandInfoRepository = new W3CWireProtocolCommandInfoRepository();
            }

            return toReturn;
        }