I wish to run my selenium tests in a different browser language. I have tried two SO answers and even the BrowserStack support without success.
I had hoped this would be a quick and easy fix, but what looks like simple code is failing in a manner I do not understand. Can anyone either provide a working code snippet, or a good idea where this one is going wrong?
[This answer]How to set Browser Language using RemoteWebDriver and [this answer]How to set browser language in selenium remote webdriver capabilities have both been tried in the following code:
DesiredCapabilities DesCaps = new DesiredCapabilities();
DesCaps.SetCapability("browserstack.user", "your_user");
DesCaps.SetCapability("browserstack.key", "your_key");
FirefoxProfile fp = new FirefoxProfile();
fp.SetPreference("intl.accept_languages", "en-US");
DesCaps.SetCapability(FirefoxDriver.ProfileCapabilityName, fp);
ChromeOptions options = new ChromeOptions();
options.AddArguments("--lang=en-DE");
DesCaps.SetCapability(ChromeOptions.Capability, options);
RemoteWebDriver driver = new RemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), DesCaps, TimeSpan.FromSeconds(500));
driver.Navigate().GoToUrl("http://google.com");
Console.WriteLine("Completed!");
Console.ReadKey();
I receive an exception when I try to start the driver:
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=The property '#/' contains additional properties ["BinaryLocation", "LeaveBrowserRunning", "Arguments", "Extensions", "DebuggerAddress", "MinidumpPath", "PerformanceLoggingPreferences", "UseSpecCompliantProtocol", "BrowserName", "BrowserVersion", "PlatformName", "AcceptInsecureCertificates", "UnhandledPromptBehavior", "PageLoadStrategy", "Proxy"] outside of the schema when none are allowed in chromeOptions
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(Uri remoteAddress, ICapabilities desiredCapabilities, TimeSpan commandTimeout)
From the code snippet, I see you have specified the browser options for Chrome and Firefox in the same script. You will need to have a separate test script for Chrome and Firefox.
-For creating a session on Chrome browser include the capabilities as below
DesiredCapabilities capability;
ChromeOptions options = new ChromeOptions();
// Set browser language to French
options.AddArguments("--lang=fr");
capability = (DesiredCapabilities)options.ToCapabilities();
capability.SetCapability("browser", "chrome");
capability.SetCapability("browser_version", "61");
capability.SetCapability("os", "Windows");
capability.SetCapability("os_version", "7");
capability.SetCapability("browserstack.user", "USERNAME");// add username
capability.SetCapability("browserstack.key", "ACCESS_KEY"); //add automate-key
driver = new ScreenShotRemoteWebDriver(new Uri("http://hub-cloud.browserstack.com/wd/hub/"), capability);
-For creating a session on Firefox browser include the capabilities as below
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability("browser", "Firefox");
capability.SetCapability("browser_version", "63.0");
capability.SetCapability("os", "Windows");
capability.SetCapability("os_version", "10");
capability.SetCapability("browserstack.user", "your_usernmae");
capability.SetCapability("browserstack.key","your_access_key");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.SetPreference("intl.accept_languages", "fr");
capability.SetCapability(FirefoxDriver.ProfileCapabilityName, firefoxProfile.ToBase64String());
For more information on passing browser options using C# refer - https://www.browserstack.com/automate/c-sharp
BrowserStack Support kindly supplied two working examples:
{
IWebDriver driver;
FirefoxOptions options = new FirefoxOptions();
options.AddAdditionalCapability("browser", "firefox", true);
options.AddAdditionalCapability("os", "Windows", true);
options.AddAdditionalCapability("os_version", "10", true);
options.AddAdditionalCapability("browser_version", "63.0", true);
options.AddAdditionalCapability("build", "BuildName", true);
options.SetPreference("intl.accept_languages", "de");
driver = new RemoteWebDriver(new Uri("http://your_username:your_access_key@hub-cloud.browserstack.com/wd/hub/"),
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);
Thread.Sleep(2000);
driver.Navigate().GoToUrl("http://www.amazon.in");
Console.WriteLine(driver.Title);
driver.Quit();
}
}
and in Chrome:
IWebDriver driver;
ChromeOptions options = new ChromeOptions();
options.AddAdditionalCapability("browser", "chrome", true);
options.AddAdditionalCapability("os", "Windows", true);
options.AddAdditionalCapability("os_version", "10", true);
options.AddAdditionalCapability("browser_version", "69.0", true);
options.AddAdditionalCapability("build", "BuildName", true);
options.AddArgument("--lang=de");
driver = new RemoteWebDriver(new Uri("http://your_username:your_access_key@hub-cloud.browserstack.com/wd/hub/"),
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);
Thread.Sleep(2000);
driver.Navigate().GoToUrl("http://www.amazon.in");
Console.WriteLine(driver.Title);
driver.Quit();
User contributions licensed under CC BY-SA 3.0