11using Aquality . Selenium . Core . Localization ;
2+ using Aquality . Selenium . Logging ;
23using Newtonsoft . Json . Linq ;
34using OpenQA . Selenium ;
45using OpenQA . Selenium . Chromium ;
@@ -92,15 +93,16 @@ public DevToolsSession GetDevToolsSession(int protocolVersion)
9293 /// </summary>
9394 /// <param name="commandName">Name of the command to execute.</param>
9495 /// <param name="commandParameters">Parameters of the command to execute.</param>
96+ /// <param name="loggingOptions">Logging preferences.</param>
9597 /// <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 )
9799 {
98100 if ( devToolsProvider is ChromiumDriver driver )
99101 {
100- LogCommand ( commandName , JToken . FromObject ( commandParameters ) ) ;
102+ LogCommand ( commandName , JToken . FromObject ( commandParameters ) , loggingOptions ) ;
101103 var result = driver . ExecuteCdpCommand ( commandName , commandParameters ) ;
102104 var formattedResult = JToken . FromObject ( result ) ;
103- LogCommandResult ( formattedResult ) ;
105+ LogCommandResult ( formattedResult , loggingOptions ) ;
104106 return result ;
105107 }
106108 else
@@ -117,15 +119,17 @@ public object ExecuteCdpCommand(string commandName, Dictionary<string, object> c
117119 /// <param name="cancellationToken">A CancellationToken object to allow for cancellation of the command.</param>
118120 /// <param name="millisecondsTimeout">The execution timeout of the command in milliseconds.</param>
119121 /// <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>
120123 /// <returns>A JToken based on a command created with the specified command name and parameters.</returns>
121124 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 )
123127 {
124128 var parameters = commandParameters ?? new JObject ( ) ;
125- LogCommand ( commandName , parameters ) ;
129+ LogCommand ( commandName , parameters , loggingOptions ) ;
126130 var result = await devToolsProvider . GetDevToolsSession ( )
127131 . SendCommand ( commandName , parameters , cancellationToken , millisecondsTimeout , throwExceptionIfResponseNotReceived ) ;
128- LogCommandResult ( result ) ;
132+ LogCommandResult ( result , loggingOptions ) ;
129133 return result ;
130134 }
131135
@@ -144,21 +148,33 @@ public async Task<JToken> SendCommand(ICommand commandWithParameters,
144148 cancellationToken , millisecondsTimeout , throwExceptionIfResponseNotReceived ) ;
145149 }
146150
147- private void LogCommand ( string commandName , JToken commandParameters )
151+ private void LogCommand ( string commandName , JToken commandParameters , DevToolsCommandLoggingOptions loggingOptions = null )
148152 {
153+ if ( loggingOptions == null )
154+ {
155+ loggingOptions = new DevToolsCommandLoggingOptions ( ) ;
156+ }
157+ if ( ! loggingOptions . Result . Enabled )
158+ {
159+ return ;
160+ }
149161 if ( commandParameters . Any ( ) )
150162 {
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 ( ) ) ;
152164 }
153165 else
154166 {
155- Logger . Info ( "loc.browser.devtools.command.execute" , commandName ) ;
167+ Logger . LogByLevel ( loggingOptions . Command . LogLevel , "loc.browser.devtools.command.execute" , commandName ) ;
156168 }
157169 }
158170
159- private void LogCommandResult ( JToken result )
171+ private void LogCommandResult ( JToken result , DevToolsCommandLoggingOptions loggingOptions = null )
160172 {
161- if ( result . Any ( ) )
173+ if ( loggingOptions == null )
174+ {
175+ loggingOptions = new DevToolsCommandLoggingOptions ( ) ;
176+ }
177+ if ( result . Any ( ) && loggingOptions . Result . Enabled )
162178 {
163179 Logger . Info ( "loc.browser.devtools.command.execute.result" , result . ToString ( ) ) ;
164180 }
0 commit comments