Last active
March 6, 2024 16:24
-
-
Save nadvolod/ac8cdf55889510fcd64434d4ee1e2a60 to your computer and use it in GitHub Desktop.
Add a Chrome extension to RemoteWebDriver using Selenium and C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private IWebDriver GetRemoteDriver() | |
{ | |
//1. Getting the path to my extension | |
var outPutDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); | |
ChromeOptions options = new ChromeOptions(); | |
options.AddExtension(outPutDirectory + @"\3.1.3_0.crx"); | |
//2. Adding the appropriate capabilities | |
//---- >>>> Don't do this - Setting the browser name is redundant | |
//options.AddAdditionalCapability(CapabilityType.BrowserName, "chrome", true); | |
options.AddAdditionalCapability(CapabilityType.Version, "48.0", true); | |
options.AddAdditionalCapability(CapabilityType.Platform, "Windows 10", true); | |
options.AddAdditionalCapability("username", "Buzzingha!", true); | |
options.AddAdditionalCapability("accessKey", "flip-flop-please-just-stop", true); | |
options.AddAdditionalCapability("name", TestContext.CurrentContext.Test.Name, true); | |
//3. IMPORTANT - Notice the options.ToCapabilities() call!! | |
return new RemoteWebDriver(new Uri("http://ondemand.saucelabs.com:80/wd/hub"), options.ToCapabilities(), | |
TimeSpan.FromSeconds(600)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment