/// <summary> /// Redacts sensitive data from commands reports (only if sent to a secured element). /// </summary> /// <param name="executor">The command executor used by the driver to execute WebDriver commands.</param> /// <param name="command">The command to be redacted.</param> /// <returns>The redacted command, or the original command if no redaction is required.</returns> public static Command RedactCommand(ITestProjectCommandExecutor executor, Command command) { if (command.Name.Equals(DriverCommand.SendKeysToElement) || command.Name.Equals(DriverCommand.SendKeysToActiveElement)) { string elementId = command.Parameters.TryGetValue("id", out var elId) ? elId.ToString() : string.Empty; if (!IsRedactRequired(executor, command, elementId)) { return(command); } command.Parameters["text"] = "***"; command.Parameters["value"] = new string[] { "***" }; } return(command); }
/// <summary> /// Checks whether or not the element is a secured element. /// </summary> /// <param name="executor">The command executor used by the driver to execute WebDriver commands.</param> /// <param name="elementId">The unique ID of the element that the command was executed on.</param> /// <returns>True if the element is a secure element, false otherwise.</returns> private static bool IsSecuredElement(ITestProjectCommandExecutor executor, string elementId) { Dictionary <string, object> getAttributeParameters = new Dictionary <string, object>(); getAttributeParameters.Add("id", elementId); getAttributeParameters.Add("name", "type"); Command getAttributeCommand = new Command( new SessionId(AgentClient.GetInstance().AgentSession.SessionId), DriverCommand.GetElementAttribute, getAttributeParameters); Response response = executor.Execute(getAttributeCommand, true); string inputType = response.Status.Equals(WebDriverResult.Success) ? response.Value.ToString() : string.Empty; return(inputType.Equals("password") || inputType.Equals("XCUIElementTypeSecureTextField")); }
/// <summary> /// Initializes a new instance of the <see cref="ReportingCommandExecutor"/> class. /// </summary> /// <param name="commandExecutor">The HTTP command executor used to send WebDriver commands.</param> /// <param name="disableReports">True if all reporting should be disabled, false otherwise.</param> public ReportingCommandExecutor(ITestProjectCommandExecutor commandExecutor, bool disableReports) { this.commandExecutor = commandExecutor; this.ReportsDisabled = disableReports; }
/// <summary> /// Checks whether redaction is required. /// </summary> /// <param name="executor">The command executor used by the driver to execute WebDriver commands.</param> /// <param name="command">The command to be redacted.</param> /// <param name="elementId">The unique ID of the element that the command was executed on.</param> /// <returns>True if redaction is required, false otherwise.</returns> private static bool IsRedactRequired(ITestProjectCommandExecutor executor, Command command, string elementId) { // TODO: check if element is a mobile element and act accordingly return(IsSecuredElement(executor, elementId)); }
/// <summary> /// Initializes a new instance of the <see cref="ReportingCommandExecutor"/> class. /// </summary> /// <param name="commandExecutor">The HTTP command executor used to send WebDriver commands.</param> /// <param name="disableReports">True if all reporting should be disabled, false otherwise.</param> public ReportingCommandExecutor(ITestProjectCommandExecutor commandExecutor, bool disableReports) { this.stashedCommands = new OrderedDictionary(); this.commandExecutor = commandExecutor; this.ReportsDisabled = disableReports; }