Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.0k views
in Technique[技术] by (71.8m points)

timezone - How to set to other time zone in Cypress while running test?

cy.clock()
cy.visit('http://localhost:3333')
cy.get('#search').type('Acme Company')
cy.tick(1000)
// more test code here

// restore the clock
cy.clock().then((clock) => {
  clock.restore()
})

How to set timezone in Cypress while running test? I am in Vietnam, my time zone is GMT+7 While I run test, I want my test run in Timezone GMT+8.

question from:https://stackoverflow.com/questions/65896152/how-to-set-to-other-time-zone-in-cypress-while-running-test

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

To set a now timestamp you could use:

const now = new Date(Date.UTC(2021, 1, 26)).getTime();
cy.clock(now);

More info in the documentation: cy.clock() - Now


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...