Esempio n. 1
0
        public Response Execute(Command commandToExecute)
        {
            if (commandToExecute == null)
            {
                throw new ArgumentNullException(nameof(commandToExecute), "commandToExecute cannot be null");
            }

            var info        = CommandInfoRepository.GetCommandInfo(commandToExecute.Name);
            var requestInfo = new HttpRequestInfo(RemoteServerUri, commandToExecute, info);

            HttpResponseInfo responseInfo = MakeHttpRequest(requestInfo);

            Response toReturn = 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.
                CommandInfoRepository = new W3CWireProtocolCommandInfoRepository();
            }

            return(toReturn);
        }
Esempio n. 2
0
        public void SetCommandInfoRepository(CommandInfoRepository repository)
        {
            // this.CommandExecutor.HttpExecutor.commandInfoRepository = repository
            var commandExecutor = GetCommandExecutor(_remoteWebDriver);

            var httpExecutorProperty = commandExecutor.GetType().GetProperty("HttpExecutor");

            if (null == httpExecutorProperty)
            {
                throw new InvalidOperationException($"remoteWebDriver.CommandExecutor.HttpExecutor property should exist. {IMPLEMENTATION_NOTE}");
            }

            var executor = httpExecutorProperty.GetValue(commandExecutor);

            if (null == executor)
            {
                throw new InvalidOperationException($"remoteWebDriver.CommandExecutor.HttpExecutor property should not be null. {IMPLEMENTATION_NOTE}");
            }

            var commandInfoRepositoryField = executor.GetType().GetField("commandInfoRepository", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            if (null == commandInfoRepositoryField)
            {
                throw new InvalidOperationException($"remoteWebDriver.CommandExecutor.HttpExecutor.commandInfoRepository property should exist. {IMPLEMENTATION_NOTE}");
            }

            commandInfoRepositoryField.SetValue(executor, repository);
        }
 /// <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);
 }
 public static void AddAppCommands(this CommandInfoRepository commandInfoRepository)
 {
     commandInfoRepository.TryAddCommand(AppDriverCommand.TakeScreenshot, new CommandInfo(CommandInfo.GetCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/screenshot"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.GetSessions, new CommandInfo(CommandInfo.GetCommand, "sessions"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.RemoveSession, new CommandInfo(CommandInfo.DeleteCommand, $"session/{{{AppDriverCommand.SessionId}}}"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.GetApplications, new CommandInfo(CommandInfo.GetCommand, "quamotion/app"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.GetDevices, new CommandInfo(CommandInfo.GetCommand, "quamotion/device"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.GetDeviceInformation, new CommandInfo(CommandInfo.GetCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.GetInstalledApplications, new CommandInfo(CommandInfo.GetCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.DeleteApplication, new CommandInfo(CommandInfo.DeleteCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.DeleteSettings, new CommandInfo(CommandInfo.DeleteCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}/settings"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.InstallApplication2, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}/{{{AppDriverCommand.AppVersion}}}"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.InstallApplication, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.RebootDevice, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/reboot"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.IsReady, new CommandInfo(CommandInfo.GetCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/isReady"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.GetProperty, new CommandInfo(CommandInfo.GetCommand, $"session/{{{AppDriverCommand.SessionId}}}/element/{{{AppDriverCommand.ElementId}}}/property/{{{AppDriverCommand.PropertyName}}}"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.ElementByCoordinates, new CommandInfo(CommandInfo.GetCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/elementByCoordinates"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.GetStatus, new CommandInfo(CommandInfo.GetCommand, $"status"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.DismissKeyboard, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/dismissKeyboard"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.ClearText, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/clear"));
     commandInfoRepository.TryAddCommand(AppDriverCommand.ScrollTo, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/element/{{{AppDriverCommand.ElementId}}}/quamotion/scrollTo"));
 }
        public static void AddAppCommands(this CommandInfoRepository commandInfoRepository)
        {
            // update some routes to match Quamotion WebDriver
            var field             = typeof(CommandInfoRepository).GetField("commandDictionary", BindingFlags.Instance | BindingFlags.NonPublic);
            var commandDictionary = field.GetValue(commandInfoRepository) as Dictionary <string, CommandInfo>;

            commandDictionary["sendKeysToActiveElement"] = new CommandInfo(CommandInfo.PostCommand, "/session/{sessionId}/keys");
            commandDictionary["getWindowSize"]           = new CommandInfo(CommandInfo.GetCommand, "/session/{sessionId}/window/size");

            commandInfoRepository.TryAddCommand(AppDriverCommand.TakeScreenshot, new CommandInfo(CommandInfo.GetCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/screenshot"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetSessions, new CommandInfo(CommandInfo.GetCommand, "sessions"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.RemoveSession, new CommandInfo(CommandInfo.DeleteCommand, $"session/{{{AppDriverCommand.SessionId}}}"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetApplications, new CommandInfo(CommandInfo.GetCommand, "quamotion/app"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetDevices, new CommandInfo(CommandInfo.GetCommand, "quamotion/device"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetDeviceInformation, new CommandInfo(CommandInfo.GetCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetInstalledApplications, new CommandInfo(CommandInfo.GetCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.DeleteApplication, new CommandInfo(CommandInfo.DeleteCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.DeleteSettings, new CommandInfo(CommandInfo.DeleteCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}/settings"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.InstallApplication2, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}/{{{AppDriverCommand.AppVersion}}}"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.InstallApplication, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.RebootDevice, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/reboot"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.StartApplication, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}/launch?strict"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.IsReady, new CommandInfo(CommandInfo.GetCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/isReady"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetProperty, new CommandInfo(CommandInfo.GetCommand, $"session/{{{AppDriverCommand.SessionId}}}/element/{{{AppDriverCommand.ElementId}}}/property/{{{AppDriverCommand.PropertyName}}}"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.SetProperty, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/element/{{{AppDriverCommand.ElementId}}}/property"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.PerformOperation, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/element/{{{AppDriverCommand.ElementId}}}/perform"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.ElementByCoordinates, new CommandInfo(CommandInfo.GetCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/elementByCoordinates"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.ClickByCoordinate, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/touch/clickByCoordinate"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.ScrollToVisible, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/element/{{{AppDriverCommand.ElementId}}}/quamotion/scrollToVisible"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetStatus, new CommandInfo(CommandInfo.GetCommand, $"status"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.DismissKeyboard, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/dismissKeyboard"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.ClearText, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/quamotion/clear"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.ScrollTo, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/element/{{{AppDriverCommand.ElementId}}}/quamotion/scrollTo"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.GetTimeouts, new CommandInfo(CommandInfo.GetCommand, $"session/{{{AppDriverCommand.SessionId}}}/timeouts"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.FlickCoordinate, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/touch/flick"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.KillApplication, new CommandInfo(CommandInfo.PostCommand, $"quamotion/device/{{{AppDriverCommand.DeviceId}}}/app/{{{AppDriverCommand.AppId}}}/kill?strict"));
            commandInfoRepository.TryAddCommand(AppDriverCommand.SendKeys, new CommandInfo(CommandInfo.PostCommand, $"session/{{{AppDriverCommand.SessionId}}}/keys"));
        }
Esempio n. 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TypedHttpCommandExecutor"/> class.
        /// </summary>
        /// <param name="remoteServer">
        /// The <see cref="Uri"/> of the <c>WebDriver</c> server
        /// </param>
        /// <param name="commandInfoRepository">
        /// The <see cref="CommandInfoRepository"/> used to convert <see cref="Command"/> objects to <see cref="WebRequest"/>.
        /// </param>
        public TypedHttpCommandExecutor(Uri remoteServer, CommandInfoRepository commandInfoRepository)
        {
            if (commandInfoRepository == null)
            {
                throw new ArgumentNullException(nameof(commandInfoRepository));
            }

            if (remoteServer == null)
            {
                throw new ArgumentNullException(nameof(remoteServer));
            }

            if (!remoteServer.AbsoluteUri.EndsWith("/", StringComparison.OrdinalIgnoreCase))
            {
                remoteServer = new Uri(remoteServer.ToString() + "/");
            }

            this.RemoteServer = remoteServer;
            ServicePointManager.Expect100Continue            = false;
            HttpWebRequest.DefaultMaximumErrorResponseLength = -1;

            this.CommandInfoRepository = commandInfoRepository;
        }