Cypress: Accept timezone as configuration

Created on 8 Dec 2017  路  14Comments  路  Source: cypress-io/cypress

It remains to be seen if all browser respect this - but setting the TZ environment variable seems to make chrome change the timezone accordingly.

If this is the case we can accept this as a config value in cypress.json and automatically pass this in when spawning the browser.

1锔忊儯 existing workaround ready for work feature

Most helpful comment

In package.json:

"scripts": {
  "cypress:open": "TZ=America/New_York cypress open",
  "cypress:run": "TZ=America/New_York cypress run"
}

UTC example:

"scripts": {
  "cypress:open": "TZ=Etc/UTC yarn cypress open",
  "cypress:run": "TZ=Etc/UTC yarn cypress run"
}

In Circle config:

environment:
  TZ: "/usr/share/zoneinfo/America/New_York"

UTC example:

environment:
  TZ: '/usr/share/zoneinfo/UTC'

All 14 comments

This will be necessary for supporting snapshot visual regression testing, whether from Cypress itself or usage of third party libraries like cypress-image-snapshot. Without it, any page that shows timezone or relative time information won't be able to be covered by automated visual testing.

Any update on this?

@Songyu-Wang No work has been done on this issue

Setting TZ=UTC worked for me.

Does this actually work on Windows as well?

@jeremy-ebler-vineti, in which file did you put this?

TZ should be set as an environment variable on the machine you are running the Cypress tests, so in our npm script, we have something like TZ=America/New_York cypress run

This should work on Windows machines, you just need to make sure to set the environment variable correctly.

Also, many CI providers have a way to set timezone in their configuration, which may be what you want to set up.

@jennifer-shehane Can you please give a code example? I can't get it to work. Thanks a lot

In package.json:

"scripts": {
  "cypress:open": "TZ=America/New_York cypress open",
  "cypress:run": "TZ=America/New_York cypress run"
}

UTC example:

"scripts": {
  "cypress:open": "TZ=Etc/UTC yarn cypress open",
  "cypress:run": "TZ=Etc/UTC yarn cypress run"
}

In Circle config:

environment:
  TZ: "/usr/share/zoneinfo/America/New_York"

UTC example:

environment:
  TZ: '/usr/share/zoneinfo/UTC'

Thank you very much for the response. I have a cypress.json and a cypress.env.json. Does the environment part go in there? Or what do you mean with Circle config?

@Delfgou https://circleci.com/docs/2.0/faq/#how-can-i-set-the-timezone-in-docker-images

Ah but then it only works when I run the test as part of the pipeline? Is there a way to mock the timezone when I run the test locally?

Yes, with OS level environment variables as already mentioned. Please search in Google for "setting timezone via environment variables" for your OS.

ok thanks

Was this page helpful?
0 / 5 - 0 ratings