Skip to content

Instantly share code, notes, and snippets.

@jimevans
Last active April 24, 2020 13:59
Show Gist options
  • Select an option

  • Save jimevans/eea715368ea3ae664099ab5ce409d686 to your computer and use it in GitHub Desktop.

Select an option

Save jimevans/eea715368ea3ae664099ab5ce409d686 to your computer and use it in GitHub Desktop.
HttpCommandExecutor commandExecutor = new HttpCommandExecutor(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), TimeSpan.FromSeconds(60));
commandExecutor.Proxy = new WebProxy("http://address:port", false);
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("browser", "Chrome");
options.AddAdditionalCapability("browser_version", "80.0");
options.AddAdditionalCapability("os", "Windows");
options.AddAdditionalCapability("os_version", "10");
options.AddAdditionalCapability("resolution", "1024x768");
options.AddAdditionalCapability("browserstack.user", "user");
options.AddAdditionalCapability("browserstack.key", "key");
options.AddAdditionalCapability("name", "Bstack-[C_sharp] Sample Test");
IWebDriver driver = new RemoteWebDriver(commandExecutor, options.ToCapabilities());
driver.Navigate().GoToUrl("http://www.google.com");
Console.WriteLine(driver.Title);
IWebElement query = driver.FindElement(By.Name("q"));
query.SendKeys("Browserstack");
query.Submit();
Console.WriteLine(driver.Title);
driver.Quit();
@mireshsonkamble
Copy link
Copy Markdown

mireshsonkamble commented Apr 24, 2020

HttpCommandExecutor commandExecutor = new HttpCommandExecutor(new Uri("http://hub-cloud.browserstack.com/wd/hub/", TimeSpan.FromSeconds(60));
In the above line ")" is missing after the hub URL

Also options.AddAdditionalCapability("", "","true"); acceps three arguments and last argument should be true.

@jimevans
Copy link
Copy Markdown
Author

Good catch, @maddysk3. I was writing this from memory, without the aid of an IDE, and missed the closing parenthesis.

As for the AddAdditionalCapability, this particular gist was provided as an answer to a specific question from a Selenium user. In their code, they did not use the three-argument overload of AddAdditionalCapability; they used the two-argument overload, and I was deliberately preserving their choice of which method to call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment