1
1
using Aquality . Selenium . Core . Localization ;
2
+ using Aquality . Selenium . Logging ;
2
3
using Newtonsoft . Json . Linq ;
3
4
using OpenQA . Selenium ;
4
5
using OpenQA . Selenium . Chromium ;
@@ -92,15 +93,16 @@ public DevToolsSession GetDevToolsSession(int protocolVersion)
92
93
/// </summary>
93
94
/// <param name="commandName">Name of the command to execute.</param>
94
95
/// <param name="commandParameters">Parameters of the command to execute.</param>
96
+ /// <param name="loggingOptions">Logging preferences.</param>
95
97
/// <returns>An object representing the result of the command, if applicable.</returns>
96
- public object ExecuteCdpCommand ( string commandName , Dictionary < string , object > commandParameters )
98
+ public object ExecuteCdpCommand ( string commandName , Dictionary < string , object > commandParameters , DevToolsCommandLoggingOptions loggingOptions = null )
97
99
{
98
100
if ( devToolsProvider is ChromiumDriver driver )
99
101
{
100
- LogCommand ( commandName , JToken . FromObject ( commandParameters ) ) ;
102
+ LogCommand ( commandName , JToken . FromObject ( commandParameters ) , loggingOptions ) ;
101
103
var result = driver . ExecuteCdpCommand ( commandName , commandParameters ) ;
102
104
var formattedResult = JToken . FromObject ( result ) ;
103
- LogCommandResult ( formattedResult ) ;
105
+ LogCommandResult ( formattedResult , loggingOptions ) ;
104
106
return result ;
105
107
}
106
108
else
@@ -117,15 +119,17 @@ public object ExecuteCdpCommand(string commandName, Dictionary<string, object> c
117
119
/// <param name="cancellationToken">A CancellationToken object to allow for cancellation of the command.</param>
118
120
/// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
119
121
/// <param name="throwExceptionIfResponseNotReceived"><see langword="true"/> to throw an exception if a response is not received; otherwise, <see langword="false"/>.</param>
122
+ /// <param name="loggingOptions">Logging preferences.</param>
120
123
/// <returns>A JToken based on a command created with the specified command name and parameters.</returns>
121
124
public async Task < JToken > SendCommand ( string commandName , JToken commandParameters = null ,
122
- CancellationToken cancellationToken = default , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true )
125
+ CancellationToken cancellationToken = default , int ? millisecondsTimeout = null , bool throwExceptionIfResponseNotReceived = true ,
126
+ DevToolsCommandLoggingOptions loggingOptions = null )
123
127
{
124
128
var parameters = commandParameters ?? new JObject ( ) ;
125
- LogCommand ( commandName , parameters ) ;
129
+ LogCommand ( commandName , parameters , loggingOptions ) ;
126
130
var result = await devToolsProvider . GetDevToolsSession ( )
127
131
. SendCommand ( commandName , parameters , cancellationToken , millisecondsTimeout , throwExceptionIfResponseNotReceived ) ;
128
- LogCommandResult ( result ) ;
132
+ LogCommandResult ( result , loggingOptions ) ;
129
133
return result ;
130
134
}
131
135
@@ -144,21 +148,33 @@ public async Task<JToken> SendCommand(ICommand commandWithParameters,
144
148
cancellationToken , millisecondsTimeout , throwExceptionIfResponseNotReceived ) ;
145
149
}
146
150
147
- private void LogCommand ( string commandName , JToken commandParameters )
151
+ private void LogCommand ( string commandName , JToken commandParameters , DevToolsCommandLoggingOptions loggingOptions = null )
148
152
{
153
+ if ( loggingOptions == null )
154
+ {
155
+ loggingOptions = new DevToolsCommandLoggingOptions ( ) ;
156
+ }
157
+ if ( ! loggingOptions . Result . Enabled )
158
+ {
159
+ return ;
160
+ }
149
161
if ( commandParameters . Any ( ) )
150
162
{
151
- Logger . Info ( "loc.browser.devtools.command.execute.withparams" , commandName , commandParameters . ToString ( ) ) ;
163
+ Logger . LogByLevel ( loggingOptions . Command . LogLevel , "loc.browser.devtools.command.execute.withparams" , commandName , commandParameters . ToString ( ) ) ;
152
164
}
153
165
else
154
166
{
155
- Logger . Info ( "loc.browser.devtools.command.execute" , commandName ) ;
167
+ Logger . LogByLevel ( loggingOptions . Command . LogLevel , "loc.browser.devtools.command.execute" , commandName ) ;
156
168
}
157
169
}
158
170
159
- private void LogCommandResult ( JToken result )
171
+ private void LogCommandResult ( JToken result , DevToolsCommandLoggingOptions loggingOptions = null )
160
172
{
161
- if ( result . Any ( ) )
173
+ if ( loggingOptions == null )
174
+ {
175
+ loggingOptions = new DevToolsCommandLoggingOptions ( ) ;
176
+ }
177
+ if ( result . Any ( ) && loggingOptions . Result . Enabled )
162
178
{
163
179
Logger . Info ( "loc.browser.devtools.command.execute.result" , result . ToString ( ) ) ;
164
180
}
0 commit comments