/// <summary> /// Execute a command on the target browser /// </summary> /// <param name="threadId">Id used to distinguish between multiple tests running at the same time</param> /// <param name="source">HtmlElement that initiated this command, null if none</param> /// <param name="command">Command to execute</param> /// <param name="secondsTimeout">Timeout in seconds that browser shoud wait for this command</param> /// <returns>BrowserInfo object that contains command results</returns> public BrowserInfo ExecuteCommand(int threadId, HtmlElement source, BrowserCommand command, int secondsTimeout) { if (source != null) { // add id to description, to make logs more informative command.Description += " id=" + source.Id; } // fire event before any command execution is started OnBrowserCommandExecuting(new BrowserCommandEventArgs(threadId, command, secondsTimeout)); BrowserInfo browserInfo = null; BrowserCommandHandler commandHandler = null; if (this._browserCommandHandlerFactory.TryGetValue(command.Handler.ClientFunctionName, out commandHandler)) { // just call a handler and if there any exceptions, let them go browserInfo = commandHandler(threadId, source, command, secondsTimeout); } else { throw new NotSupportedException(String.Format("Command '{0}' is not supported", command.Handler.ClientFunctionName)); } return(browserInfo); }
/// <summary> /// Adds Browser Command handlers to the dictionary /// </summary> /// <param name="commandName">Command name</param> /// <param name="commandHandler">Corresponding handler</param> private void RegisterBrowserCommandHandler(string commandName, BrowserCommandHandler commandHandler) { if (string.IsNullOrEmpty(commandName)) { throw new ArgumentNullException("commandName", "Browser command name can not be null or empty."); } if (commandHandler == null) { throw new ArgumentNullException("commandHandler", "Handler for browser command can not be null."); } this._browserCommandHandlerFactory[commandName] = commandHandler; }