I can't figure out how to set a timezone when using Chromedriver. Is there some ChromeOptions argument or something?
The issue is that when I go to some sites (for example, https://whoer.net), it shows the system time that is equal to the time set on Windows. And I want to be able to change the Chromedriver's timezone somehow to perform timezone dependent testing.
I tried to set some chrome options:
Map<String, Object> chromeOptions = new HashMap<String, Object>();
chromeOptions.put("args", Arrays.asList("--disable-system-timezone-automatic-detection", "--local-timezone"));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
It doesn't work.
Tried to do some weird thing using Javascript:
((JavascriptExecutor) driver).executeScript("Date.prototype.getTime = function() { return 1 };");
It didn't help either.
EDIT:
Found this https://sqa.stackexchange.com/questions/8838/faking-system-time-date-with-selenium-webdriver
Tried to execute javascript on page with the code copied from TimeShift.js like this:
((JavascriptExecutor) driver).executeScript("/*code from TimeShift.js here*/ TimeShift.setTimezoneOffset(-60);");
System time at https://whoer.net didn't change. What am I doing wrong?
Runtime.getRuntime().exec("cmd /C time " + "16:56:10");
but this option isn't good for me since I want to perform a multithreaded test with many instances of Chromedriver at the same time and I want each instance to have it's own system time. – Delubrumvar dateYouWant = 1363798981693; Date.prototype.getTime = function() { return dateYouWant; }; console.log( (new Date).getTime() );
and like thisvar d = new Date(2012, 0, 20); Date = undefined; Date = function(){return d;}
but no luck, I keep seeing my Windows time at whoer.net. These methods supposed to work, I don't understand why they don't. Also tried to inject these pieces of code via Javascript Injector Google Chrome addon in the normal Google Chrome (not Chromedriver), no luck too. – Delubrum