-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Accept timezone as configuration #1043
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. |
This comment has been minimized.
This comment has been minimized.
@Songyu-Wang No work has been done on this issue |
Setting |
Does this actually work on Windows as well? |
@jeremy-ebler-vineti, in which file did you put this? |
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 "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:
|
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? |
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 |
Any example how to configure TZ in bitbucket? |
I wasn't able to change my local timezone in either Chrome nor Edge using any of the methods described above. I can see it's set in the Cypress runner app but it has no effect. |
I succesfully set the timezone on my tests usin the TZ variable, but I had to look around until I got to this issue to discover it. Should we add that to the Cypress documentation? |
@martinsik same for me on Windows (tried chrome and electron), Linux was fine |
After updating to the latest cypress the TZ env variable seems to have stopped working |
Setting "scripts": {
"cypress:open": "TZ=America/New_York cypress open",
"cypress:run": "TZ=America/New_York cypress run"
} Also, for anyone using - name: Test (Cypress)
uses: cypress-io/github-action@v2
with:
build: npm run build-msw
start: npm run start
wait-on: 'http://localhost:3000'
browser: chrome
env:
TZ: America/New_York |
Any updates for Windows? No matter if it is set in the |
Did anybody find a solution that works on Windows?
Why is there no configuration option for Cypress itself? 👀 |
I'm stuck at the same problem as Sparks: trying to make Cypress use a different timezone other than Windows'. I've tried setting the "TZ" env variable and neither Electron nor Edge give a damn about it. It's almost like they never thought people might want to use them for unit testing web systems... |
I'm unsure why none of the cypress-io maintainers nor this Testing Time Zones in Parallel article have addressed this but setting the time zone in Cypress does not work in Windows. I tried seemingly everything to get it to work in Windows, but to no avail. This included the following:
After seeing so many people in this thread share that they weren't able to get it to work in Windows, I ran a |
did you try to set var using SET on window? |
Yes, tried that too:
ran it with I did however come across something else: https://stackoverflow.com/a/69860846/1025177 The first problem being that Electron (haven't tested Edge yet) remembers the DevTools location, but in some cases doesn't re-apply it. Indicated by the additional fields being locked and greyed out. Edit 2: The approach described by this nice fellow works great (at least for my case with Electron): #7942 (comment) |
Setting the ENV var works fine but how can I test that my app works in different timezones? Update:
// pseudo code
it('test all timezones', () => {
if (TZ === 'UTC') {
assert(timezone).eq('12:00')
} else if (TZ === 'Europe/Paris') {
assert(timezone).eq('13:00')
}
}) It would be great to be able to do: // pseudo code
it('test in UTC', () => {
assert(timezone).eq('12:00')
})
it('test in Europe/Paris', () => {
cy.setTimezone('Europe/Paris')
assert(timezone).eq('13:00')
}) |
Documentation for this issue is quite poor and I am not sure then if fact of using docker image in CI is cause of an issue but we failed to change timezone in CI that would affect cypress environment |
Ideally this would be configurable in the An alternative solution would be to put the following code in the I didn't test it on Windows, but I think it should work on both Mac and Windows. First function is to lock the locale and the second is to lock the timezone.
|
#1043 (comment) thansk @dpage-mdsol This work for me on windows |
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.The text was updated successfully, but these errors were encountered: