public async Task <WebRect> GetElementRect(string elementId, CancellationToken cancellationToken = default(CancellationToken)) { await asyncFirefoxDriver.CheckConnected(cancellationToken).ConfigureAwait(false); if (asyncFirefoxDriver.ClientMarionette == null) { throw new Exception("error: no clientMarionette"); } var comm1 = new GetElementRectCommand(elementId); await asyncFirefoxDriver.ClientMarionette.SendRequestAsync(comm1, cancellationToken).ConfigureAwait(false); if (comm1.Error != null) { throw new WebBrowserException(comm1.Error); } return(ResultValueConverter.ToWebRect(comm1.Result)); }
public string ProcessCommand(string content) { var requestData = JsonConvert.DeserializeObject <Command>(content); var command = requestData.Name; var parameters = requestData.Parameters; string elementId = null; if (parameters == null) { throw new NullReferenceException("Parameters can not be NULL"); } JToken elementIdObject; if (parameters.TryGetValue("ID", out elementIdObject)) { elementId = elementIdObject.ToString(); } CommandBase commandToExecute; if (command.Equals("ping")) { // Service command return("<pong>"); } // TODO: Refactor similar to CommandExecutors in Driver if (command.Equals(DriverCommand.GetAlertText)) { commandToExecute = new AlertTextCommand(); } else if (command.Equals(DriverCommand.AcceptAlert)) { commandToExecute = new AlertCommand { Action = AlertCommand.With.Accept }; } else if (command.Equals(DriverCommand.DismissAlert)) { commandToExecute = new AlertCommand { Action = AlertCommand.With.Dismiss }; } else if (command.Equals(DriverCommand.FindElement) || command.Equals(DriverCommand.FindChildElement)) { commandToExecute = new ElementCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.FindElements) || command.Equals(DriverCommand.FindChildElements)) { commandToExecute = new ElementsCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.ClickElement)) { commandToExecute = new ClickCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.SendKeysToElement)) { var values = ((JArray)parameters["value"]).ToObject <List <string> >(); var value = string.Empty; if (values.Any()) { value = values.Aggregate((aggregated, next) => aggregated + next); } commandToExecute = new ValueCommand { ElementId = elementId, KeyString = value }; } else if (command.Equals(DriverCommand.GetElementText)) { commandToExecute = new TextCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.IsElementDisplayed)) { commandToExecute = new DisplayedCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementLocation)) { commandToExecute = new LocationCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementLocationOnceScrolledIntoView)) { commandToExecute = new LocationInViewCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementSize)) { commandToExecute = new GetElementSizeCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetElementRect)) { commandToExecute = new GetElementRectCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetPageSource)) { commandToExecute = new PageSourceCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.GetOrientation)) { commandToExecute = new OrientationCommand(); } else if (command.Equals(DriverCommand.GetElementAttribute)) { commandToExecute = new GetElementAttributeCommand { ElementId = elementId }; } else if (command.Equals(DriverCommand.ExecuteScript)) { commandToExecute = new ExecuteCommand(); } else if (command.Equals(ExtendedDriverCommand.InvokeAppBarItemCommand)) { commandToExecute = new InvokeAppBarItemCommand(); } else if (command.Equals(ExtendedDriverCommand.InvokeMethodCommand)) { commandToExecute = new InvokeMethodCommand(); } else { throw new NotImplementedException("Not implemented: " + command); } // TODO: Replace passing Automator to command with passing some kind of configuration commandToExecute.Automator = this; commandToExecute.Parameters = parameters; var response = commandToExecute.Do(); return(response); }