18
18
19
19
using System ;
20
20
using System . Collections . Generic ;
21
- using System . Globalization ;
22
- using System . Net . Http ;
23
- using System . Threading . Tasks ;
24
- using Newtonsoft . Json ;
25
- using Newtonsoft . Json . Linq ;
21
+ using System . Collections . ObjectModel ;
26
22
using OpenQA . Selenium . DevTools ;
27
23
using OpenQA . Selenium . Remote ;
28
24
@@ -31,70 +27,107 @@ namespace OpenQA.Selenium.Chromium
31
27
/// <summary>
32
28
/// Provides an abstract way to access Chromium-based browsers to run tests.
33
29
/// </summary>
34
- public abstract class ChromiumDriver : WebDriver , ISupportsLogs , IDevTools
30
+ public class ChromiumDriver : WebDriver , ISupportsLogs , IDevTools
35
31
{
36
32
/// <summary>
37
33
/// Accept untrusted SSL Certificates
38
34
/// </summary>
39
35
public static readonly bool AcceptUntrustedCertificates = true ;
40
36
41
- protected const string ExecuteCdp = "executeCdpCommand" ;
42
- protected const string GetCastSinksCommand = "getCastSinks" ;
43
- protected const string SelectCastSinkCommand = "selectCastSink" ;
44
- protected const string StartCastTabMirroringCommand = "startCastTabMirroring" ;
45
- protected const string GetCastIssueMessageCommand = "getCastIssueMessage" ;
46
- protected const string StopCastingCommand = "stopCasting" ;
47
- private const string GetNetworkConditionsCommand = "getNetworkConditions" ;
48
- private const string SetNetworkConditionsCommand = "setNetworkConditions" ;
49
- private const string DeleteNetworkConditionsCommand = "deleteNetworkConditions" ;
50
- private const string SendChromeCommand = "sendChromeCommand" ;
51
- private const string SendChromeCommandWithResult = "sendChromeCommandWithResult" ;
52
- private const string LaunchAppCommand = "launchAppCommand" ;
53
- private const string SetPermissionCommand = "setPermission" ;
37
+ /// <summary>
38
+ /// Command for executing a Chrome DevTools Protocol command in a driver for a Chromium-based browser.
39
+ /// </summary>
40
+ public static readonly string ExecuteCdp = "executeCdpCommand" ;
54
41
55
- private readonly string optionsCapabilityName ;
56
- private DevToolsSession devToolsSession ;
42
+ /// <summary>
43
+ /// Command for getting cast sinks in a driver for a Chromium-based browser.
44
+ /// </summary>
45
+ public static readonly string GetCastSinksCommand = "getCastSinks" ;
57
46
58
47
/// <summary>
59
- /// Initializes a new instance of the <see cref="ChromiumDriver"/> class using the specified
60
- /// <see cref="ChromiumDriverService"/> and options.
48
+ /// Command for selecting a cast sink in a driver for a Chromium-based browser.
61
49
/// </summary>
62
- /// <param name="service">The <see cref="ChromiumDriverService"/> to use.</param>
63
- /// <param name="options">The <see cref="ChromiumOptions"/> used to initialize the driver.</param>
64
- public ChromiumDriver ( ChromiumDriverService service , ChromiumOptions options )
65
- : this ( service , options , RemoteWebDriver . DefaultCommandTimeout )
50
+ public static readonly string SelectCastSinkCommand = "selectCastSink" ;
51
+
52
+ /// <summary>
53
+ /// Command for starting cast tab mirroring in a driver for a Chromium-based browser.
54
+ /// </summary>
55
+ public static readonly string StartCastTabMirroringCommand = "startCastTabMirroring" ;
56
+
57
+ /// <summary>
58
+ /// Command for getting a cast issued message in a driver for a Chromium-based browser.
59
+ /// </summary>
60
+ public static readonly string GetCastIssueMessageCommand = "getCastIssueMessage" ;
61
+
62
+ /// <summary>
63
+ /// Command for stopping casting in a driver for a Chromium-based browser.
64
+ /// </summary>
65
+ public static readonly string StopCastingCommand = "stopCasting" ;
66
+
67
+ /// <summary>
68
+ /// Command for getting the simulated network conditions in a driver for a Chromium-based browser.
69
+ /// </summary>
70
+ public static readonly string GetNetworkConditionsCommand = "getNetworkConditions" ;
71
+
72
+ /// <summary>
73
+ /// Command for setting the simulated network conditions in a driver for a Chromium-based browser.
74
+ /// </summary>
75
+ public static readonly string SetNetworkConditionsCommand = "setNetworkConditions" ;
76
+
77
+ /// <summary>
78
+ /// Command for deleting the simulated network conditions in a driver for a Chromium-based browser.
79
+ /// </summary>
80
+ public static readonly string DeleteNetworkConditionsCommand = "deleteNetworkConditions" ;
81
+
82
+ /// <summary>
83
+ /// Command for executing a Chrome DevTools Protocol command in a driver for a Chromium-based browser.
84
+ /// </summary>
85
+ public static readonly string SendChromeCommand = "sendChromeCommand" ;
86
+
87
+ /// <summary>
88
+ /// Command for executing a Chrome DevTools Protocol command that returns a result in a driver for a Chromium-based browser.
89
+ /// </summary>
90
+ public static readonly string SendChromeCommandWithResult = "sendChromeCommandWithResult" ;
91
+
92
+ /// <summary>
93
+ /// Command for launching an app in a driver for a Chromium-based browser.
94
+ /// </summary>
95
+ public static readonly string LaunchAppCommand = "launchAppCommand" ;
96
+
97
+ /// <summary>
98
+ /// Command for setting permissions in a driver for a Chromium-based browser.
99
+ /// </summary>
100
+ public static readonly string SetPermissionCommand = "setPermission" ;
101
+
102
+ private readonly string optionsCapabilityName ;
103
+ private DevToolsSession devToolsSession ;
104
+
105
+ private static Dictionary < string , CommandInfo > chromiumCustomCommands = new Dictionary < string , CommandInfo > ( )
66
106
{
67
- }
107
+ { GetNetworkConditionsCommand , new HttpCommandInfo ( HttpCommandInfo . GetCommand , "/session/{sessionId}/chromium/network_conditions" ) } ,
108
+ { SetNetworkConditionsCommand , new HttpCommandInfo ( HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/network_conditions" ) } ,
109
+ { DeleteNetworkConditionsCommand , new HttpCommandInfo ( HttpCommandInfo . DeleteCommand , "/session/{sessionId}/chromium/network_conditions" ) } ,
110
+ { SendChromeCommand , new HttpCommandInfo ( HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/send_command" ) } ,
111
+ { SendChromeCommandWithResult , new HttpCommandInfo ( HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/send_command_and_get_result" ) } ,
112
+ { LaunchAppCommand , new HttpCommandInfo ( HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/launch_app" ) } ,
113
+ { SetPermissionCommand , new HttpCommandInfo ( HttpCommandInfo . PostCommand , "/session/{sessionId}/permissions" ) }
114
+ } ;
68
115
69
116
/// <summary>
70
117
/// Initializes a new instance of the <see cref="ChromiumDriver"/> class using the specified <see cref="ChromiumDriverService"/>.
71
118
/// </summary>
72
119
/// <param name="service">The <see cref="ChromiumDriverService"/> to use.</param>
73
120
/// <param name="options">The <see cref="ChromiumOptions"/> to be used with the ChromiumDriver.</param>
74
121
/// <param name="commandTimeout">The maximum amount of time to wait for each command.</param>
75
- public ChromiumDriver ( ChromiumDriverService service , ChromiumOptions options , TimeSpan commandTimeout )
122
+ protected ChromiumDriver ( ChromiumDriverService service , ChromiumOptions options , TimeSpan commandTimeout )
76
123
: base ( new DriverServiceCommandExecutor ( service , commandTimeout ) , ConvertOptionsToCapabilities ( options ) )
77
124
{
78
125
this . optionsCapabilityName = options . CapabilityName ;
79
-
80
- // Add the custom commands unique to Chrome
81
- this . AddCustomChromeCommand ( GetNetworkConditionsCommand , HttpCommandInfo . GetCommand , "/session/{sessionId}/chromium/network_conditions" ) ;
82
- this . AddCustomChromeCommand ( SetNetworkConditionsCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/network_conditions" ) ;
83
- this . AddCustomChromeCommand ( DeleteNetworkConditionsCommand , HttpCommandInfo . DeleteCommand , "/session/{sessionId}/chromium/network_conditions" ) ;
84
- this . AddCustomChromeCommand ( SendChromeCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/send_command" ) ;
85
- this . AddCustomChromeCommand ( SendChromeCommandWithResult , HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/send_command_and_get_result" ) ;
86
- this . AddCustomChromeCommand ( LaunchAppCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/chromium/launch_app" ) ;
87
- this . AddCustomChromeCommand ( SetPermissionCommand , HttpCommandInfo . PostCommand , "/session/{sessionId}/permissions" ) ;
88
126
}
89
127
90
- /// <summary>
91
- /// Initializes a new instance of the <see cref="ChromiumDriver"/> class
92
- /// </summary>
93
- /// <param name="commandExecutor">An <see cref="ICommandExecutor"/> object which executes commands for the driver.</param>
94
- /// <param name="desiredCapabilities">An <see cref="ICapabilities"/> object containing the desired capabilities of the browser.</param>
95
- protected ChromiumDriver ( ICommandExecutor commandExecutor , ICapabilities desiredCapabilities )
96
- : base ( commandExecutor , desiredCapabilities )
128
+ protected static IReadOnlyDictionary < string , CommandInfo > ChromiumCustomCommands
97
129
{
130
+ get { return new ReadOnlyDictionary < string , CommandInfo > ( chromiumCustomCommands ) ; }
98
131
}
99
132
100
133
/// <summary>
@@ -140,7 +173,7 @@ public ChromiumNetworkConditions NetworkConditions
140
173
}
141
174
142
175
Dictionary < string , object > parameters = new Dictionary < string , object > ( ) ;
143
- parameters [ "network_conditions" ] = value . ToDictionary ( ) ;
176
+ parameters [ "network_conditions" ] = value ;
144
177
this . Execute ( SetNetworkConditionsCommand , parameters ) ;
145
178
}
146
179
}
@@ -291,6 +324,14 @@ public void CloseDevToolsSession()
291
324
}
292
325
}
293
326
327
+ /// <summary>
328
+ /// Clears simulated network conditions.
329
+ /// </summary>
330
+ public void ClearNetworkConditions ( )
331
+ {
332
+ this . Execute ( DeleteNetworkConditionsCommand , null ) ;
333
+ }
334
+
294
335
/// <summary>
295
336
/// Returns the list of cast sinks (Cast devices) available to the Chrome media router.
296
337
/// </summary>
@@ -401,11 +442,5 @@ private static ICapabilities ConvertOptionsToCapabilities(ChromiumOptions option
401
442
402
443
return options . ToCapabilities ( ) ;
403
444
}
404
-
405
- protected void AddCustomChromeCommand ( string commandName , string method , string resourcePath )
406
- {
407
- HttpCommandInfo commandInfoToAdd = new HttpCommandInfo ( method , resourcePath ) ;
408
- this . CommandExecutor . TryAddCommand ( commandName , commandInfoToAdd ) ;
409
- }
410
445
}
411
446
}
0 commit comments