So we have a set of selenium regression tests developed in .Net/C#/Selenium. These tests run fine locally and until BST kicked in recently they also ran fine within our azure pipeline. Since BST a small selection of tests which use times and dates are failing in azure only.
The problem is the test site is in the UK but the azure system is not so we need to make Chrome think it is still in the UK. Below is the code for setting up our chromedriver.
protected static IWebDriver? _driver = null;
var options = new ChromeOptions();
options.AddArgument("enable-automation");
options.AddArgument("disable-dev-shm-usage");
options.AddArgument("ignore-certificate-errors");
options.AddArgument("ignore-ssl-errors");
options.AddArgument("disable-popup-blocking");
options.AddArgument("lang=en");
options.AddArgument("window-size=1920,1080");
if (!System.Diagnostics.Debugger.IsAttached)
{
_isDebug = false;
options.AddArgument("headless");
}
options.AddArgument("disable-gpu");
options.AddUserProfilePreference("download.default_directory", _downloadPath);
options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("download.directory_upgrade", true);
ChromeDriverService serviceObj = ChromeDriverService.CreateDefaultService();
_driver = new ChromeDriver(serviceObj, options, TimeSpan.FromSeconds(_maxWait));
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Cookies.DeleteAllCookies();
_driver.Manage().Window.Maximize();
Now I believe IDevTools is what is required but I cannot seem to find a workable example. Can anyone assist please.
What I am basicly looking for is a way of doing this at the start of each Feature so that the browser will use London
So far I have found
var devTools = _driver as IDevTools;
var session = devTools.GetDevToolsSession();
But not sure what is next
Thanks in advance
Kev
This would appear to be the solutions, test runs in azure are passing
var options = new ChromeOptions();
options.AddArgument("enable-automation");
options.AddArgument("disable-dev-shm-usage");
options.AddArgument("ignore-certificate-errors");
options.AddArgument("ignore-ssl-errors");
options.AddArgument("disable-popup-blocking");
options.AddArgument("window-size=1920,1080");
if (!System.Diagnostics.Debugger.IsAttached)
{
_isDebug = false;
options.AddArgument("headless");
}
options.AddArgument("disable-gpu");
options.AddUserProfilePreference("download.default_directory", _downloadPath);
options.AddUserProfilePreference("profile.default_content_setting_values.automatic_downloads", 1);
options.AddUserProfilePreference("plugins.always_open_pdf_externally", true);
options.AddUserProfilePreference("download.prompt_for_download", false);
options.AddUserProfilePreference("download.directory_upgrade", true);
ChromeDriverService serviceObj = ChromeDriverService.CreateDefaultService();
_driver = new ChromeDriver(serviceObj, options, TimeSpan.FromSeconds(_maxWait));
_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Timeouts().AsynchronousJavaScript = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Timeouts().PageLoad = TimeSpan.FromSeconds(_maxWait);
_driver.Manage().Cookies.DeleteAllCookies();
_driver.Manage().Window.Maximize();
_driver.ExecuteCdpCommand(
"Emulation.setTimezoneOverride",
new Dictionary<string, object>
{
["timezoneId"] = "Europe/London"
});