Skip to content

Commit 90e8e61

Browse files
committed
[dotnet] implement ability for Chrome and Edge to set applicable permissions on browser
1 parent 232bd58 commit 90e8e61

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

dotnet/src/webdriver/Chromium/ChromiumDriver.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public abstract class ChromiumDriver : WebDriver, ISupportsLogs, IDevTools
5050
private const string SendChromeCommand = "sendChromeCommand";
5151
private const string SendChromeCommandWithResult = "sendChromeCommandWithResult";
5252
private const string LaunchAppCommand = "launchAppCommand";
53+
private const string SetPermissionCommand = "setPermission";
5354

5455
private readonly string optionsCapabilityName;
5556
private DevToolsSession devToolsSession;
@@ -83,6 +84,7 @@ public ChromiumDriver(ChromiumDriverService service, ChromiumOptions options, Ti
8384
this.AddCustomChromeCommand(SendChromeCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command");
8485
this.AddCustomChromeCommand(SendChromeCommandWithResult, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/send_command_and_get_result");
8586
this.AddCustomChromeCommand(LaunchAppCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/chromium/launch_app");
87+
this.AddCustomChromeCommand(SetPermissionCommand, HttpCommandInfo.PostCommand, "/session/{sessionId}/permissions");
8688
}
8789

8890
/// <summary>
@@ -151,6 +153,31 @@ public void LaunchApp(string id)
151153
this.Execute(LaunchAppCommand, parameters);
152154
}
153155

156+
/// <summary>
157+
/// Set supported permission on browser.
158+
/// </summary>
159+
/// <param name="permissionName">Name of item to set the permission on.</param>
160+
/// <param name="permissionValue">Value to set the permission to.</param>
161+
public void SetPermission(string permissionName, string permissionValue)
162+
{
163+
if (permissionName == null)
164+
{
165+
throw new ArgumentNullException("permissionName", "name must not be null");
166+
}
167+
168+
if (permissionValue == null)
169+
{
170+
throw new ArgumentNullException("permissionValue", "value must not be null");
171+
}
172+
173+
Dictionary<string, object> nameParameter = new Dictionary<string, object>();
174+
nameParameter["name"] = permissionName;
175+
Dictionary<string, object> parameters = new Dictionary<string, object>();
176+
parameters["descriptor"] = nameParameter;
177+
parameters["state"] = permissionValue;
178+
this.Execute(SetPermissionCommand, parameters);
179+
}
180+
154181
/// <summary>
155182
/// Executes a custom Chrome Dev Tools Protocol Command.
156183
/// </summary>

0 commit comments

Comments
 (0)