How to set timezone in Selenium Chromedriver?

I can't figure out how to set the timezone when using Chromedriver. Is there any ChromeOptions argument or something else? I searched everywhere and didn't find it.

The problem is that when I go to some sites (like https://whoer.net ) it shows the system time equal to the time set in Windows. And I want to be able to change the Chromedriver timezone in some way to do 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);

      

This does not work.

Tried to do something weird 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 running javascript on the page with code copied from TimeShift.js like this:

((JavascriptExecutor) driver).executeScript("/*code from TimeShift.js here*/ TimeShift.setTimezoneOffset(-60);");

      

The system time https://whoer.net has not changed. What am I doing wrong?

+3


source to share


1 answer


As far as I know, you can only do this with the TZ variable or with Decker Selenium.

Have you been able to find a viable solution to this? I am trying to do the same and have found very few solutions. I am trying to do this with Python. Tz variable solution is limited to Firefox on windows, and decel selenium is a nightmare to install on windows.

UPDATED PYTHON SOLUTION (below)



os.environ ["DEBUSSY"] = "1"

CM: How to set environment variables in Python

I'm not sure if there is a Java equivalent, but this Python equivalent worked for me on Windows, but only on Firefox. If you find a Java equivalent then that's awesome, but if this issue is important to you, Python is the way to go! :). I believe you are limited to three letters in windows, but fully customized on Linux operating systems. For example UTC, GMT, etc. Etc. Hope this was helpful to you. I spent years on this, but it turns out I overdid it. Good luck!

+1


source







All Articles