Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

Is webdriver capable to run a browser with a faked time, date or time zone?

Such ability would be highly useful for my automation purposes.

Yet, I did not find any such ability in the webdriver documentation. I guess such functionality is quite sophisticated as it would require to intercept and feedback altered Kernel calls. Therefore not necessarily included into webdriver - can you tell me otherwise?

Can you suggest any other method to spoof browser time settings that works with Selenium? I am open for Windows/Linux solutions. Yet this way has to work with webdriver automation.

Thanks!

-Olivier (Indeed a great blend of people here at stackexchange.)

share|improve this question

1 Answer 1

The browser date/time functions are all JavaScript. You should be able to use Sinon.JS or TimeShift.JS to mock the date/time.

  • Inject/Add the mocking framework during tests runs
  • Mock the Date object with the JavaScript Executor
  • Set the timezone
  • Run tests

Now all calls to the internal Date object will return the shifted time.

For examples see this post with TimeShift.JS and something like this is also described in this blog post, although it uses ruby TimeCop for time sync.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.