From b99643cbe408d649b763675f7f4dfa5de17ce9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alaksiej=20Miale=C5=A1ka?= Date: Sat, 27 Jan 2024 00:34:06 +0100 Subject: [PATCH] DevTools command logging options (#248) Add optional parameter for DevTools Command/Result logging options to SendComand and ExecuteCdpCommand methods closes #246 fixes #247 --- .../Aquality.Selenium/Aquality.Selenium.xml | 3 ++- .../Browsers/DevToolsHandling.cs | 26 ++++++++----------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml index 81e26676..1584b446 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml +++ b/Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml @@ -593,7 +593,7 @@ Logging preferences. A JToken based on a command created with the specified command name and parameters. - + Sends the specified command and returns the associated command response. @@ -601,6 +601,7 @@ A CancellationToken object to allow for cancellation of the command. The execution timeout of the command in milliseconds. to throw an exception if a response is not received; otherwise, . + Logging preferences. A JToken based on a command created with the specified command name and parameters. diff --git a/Aquality.Selenium/src/Aquality.Selenium/Browsers/DevToolsHandling.cs b/Aquality.Selenium/src/Aquality.Selenium/Browsers/DevToolsHandling.cs index 4e08b79f..0137c424 100644 --- a/Aquality.Selenium/src/Aquality.Selenium/Browsers/DevToolsHandling.cs +++ b/Aquality.Selenium/src/Aquality.Selenium/Browsers/DevToolsHandling.cs @@ -140,43 +140,39 @@ public async Task SendCommand(string commandName, JToken commandParamete /// A CancellationToken object to allow for cancellation of the command. /// The execution timeout of the command in milliseconds. /// to throw an exception if a response is not received; otherwise, . + /// Logging preferences. /// A JToken based on a command created with the specified command name and parameters. public async Task SendCommand(ICommand commandWithParameters, - CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true) + CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true, + DevToolsCommandLoggingOptions loggingOptions = null) { return await SendCommand(commandWithParameters.CommandName, JToken.FromObject(commandWithParameters), - cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived); + cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived, loggingOptions); } private void LogCommand(string commandName, JToken commandParameters, DevToolsCommandLoggingOptions loggingOptions = null) { - if (loggingOptions == null) - { - loggingOptions = new DevToolsCommandLoggingOptions(); - } - if (!loggingOptions.Result.Enabled) + var logging = (loggingOptions ?? new DevToolsCommandLoggingOptions()).Command; + if (!logging.Enabled) { return; } if (commandParameters.Any()) { - Logger.LogByLevel(loggingOptions.Command.LogLevel, "loc.browser.devtools.command.execute.withparams", commandName, commandParameters.ToString()); + Logger.LogByLevel(logging.LogLevel, "loc.browser.devtools.command.execute.withparams", commandName, commandParameters.ToString()); } else { - Logger.LogByLevel(loggingOptions.Command.LogLevel, "loc.browser.devtools.command.execute", commandName); + Logger.LogByLevel(logging.LogLevel, "loc.browser.devtools.command.execute", commandName); } } private void LogCommandResult(JToken result, DevToolsCommandLoggingOptions loggingOptions = null) { - if (loggingOptions == null) - { - loggingOptions = new DevToolsCommandLoggingOptions(); - } - if (result.Any() && loggingOptions.Result.Enabled) + var logging = (loggingOptions ?? new DevToolsCommandLoggingOptions()).Result; + if (result.Any() && logging.Enabled) { - Logger.Info("loc.browser.devtools.command.execute.result", result.ToString()); + Logger.LogByLevel(logging.LogLevel, "loc.browser.devtools.command.execute.result", result.ToString()); } } }