Skip to content

Commit b99643c

Browse files
authored
DevTools command logging options (#248)
Add optional parameter for DevTools Command/Result logging options to SendComand and ExecuteCdpCommand methods closes #246 fixes #247
1 parent 1c4b33a commit b99643c

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

Aquality.Selenium/src/Aquality.Selenium/Aquality.Selenium.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Aquality.Selenium/src/Aquality.Selenium/Browsers/DevToolsHandling.cs

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -140,43 +140,39 @@ public async Task<JToken> SendCommand(string commandName, JToken commandParamete
140140
/// <param name="cancellationToken">A CancellationToken object to allow for cancellation of the command.</param>
141141
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
142142
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
143+
/// <param name="loggingOptions">Logging preferences.</param>
143144
/// <returns>A JToken based on a command created with the specified command name and parameters.</returns>
144145
public async Task<JToken> SendCommand(ICommand commandWithParameters,
145-
CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true)
146+
CancellationToken cancellationToken = default, int? millisecondsTimeout = null, bool throwExceptionIfResponseNotReceived = true,
147+
DevToolsCommandLoggingOptions loggingOptions = null)
146148
{
147149
return await SendCommand(commandWithParameters.CommandName, JToken.FromObject(commandWithParameters),
148-
cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived);
150+
cancellationToken, millisecondsTimeout, throwExceptionIfResponseNotReceived, loggingOptions);
149151
}
150152

151153
private void LogCommand(string commandName, JToken commandParameters, DevToolsCommandLoggingOptions loggingOptions = null)
152154
{
153-
if (loggingOptions == null)
154-
{
155-
loggingOptions = new DevToolsCommandLoggingOptions();
156-
}
157-
if (!loggingOptions.Result.Enabled)
155+
var logging = (loggingOptions ?? new DevToolsCommandLoggingOptions()).Command;
156+
if (!logging.Enabled)
158157
{
159158
return;
160159
}
161160
if (commandParameters.Any())
162161
{
163-
Logger.LogByLevel(loggingOptions.Command.LogLevel, "loc.browser.devtools.command.execute.withparams", commandName, commandParameters.ToString());
162+
Logger.LogByLevel(logging.LogLevel, "loc.browser.devtools.command.execute.withparams", commandName, commandParameters.ToString());
164163
}
165164
else
166165
{
167-
Logger.LogByLevel(loggingOptions.Command.LogLevel, "loc.browser.devtools.command.execute", commandName);
166+
Logger.LogByLevel(logging.LogLevel, "loc.browser.devtools.command.execute", commandName);
168167
}
169168
}
170169

171170
private void LogCommandResult(JToken result, DevToolsCommandLoggingOptions loggingOptions = null)
172171
{
173-
if (loggingOptions == null)
174-
{
175-
loggingOptions = new DevToolsCommandLoggingOptions();
176-
}
177-
if (result.Any() && loggingOptions.Result.Enabled)
172+
var logging = (loggingOptions ?? new DevToolsCommandLoggingOptions()).Result;
173+
if (result.Any() && logging.Enabled)
178174
{
179-
Logger.Info("loc.browser.devtools.command.execute.result", result.ToString());
175+
Logger.LogByLevel(logging.LogLevel, "loc.browser.devtools.command.execute.result", result.ToString());
180176
}
181177
}
182178
}

0 commit comments

Comments
 (0)