Can Cypress save current datetime to use as a variable? #16623
Unanswered
paulappl
asked this question in
Questions and Help
Replies: 2 comments 2 replies
-
Update - I see that moment is considered old. Have started looking at daysjs instead but am struggling with how to use it! |
Beta Was this translation helpful? Give feedback.
2 replies
-
I tried Cypress.moment() too. But he answers with an error. And I found a good solution. It looks like this: |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I'm writing tests for a word processor which has a save function. When the save is invoked, a status bar updates with the datetime of the last save. Clicking the button and triggering the save is fine, but I'd like to verify that the status bar has updated and it seems the logical method would be to record the time at the start of the test (as InitialDatetime for example) at the start, trigger the save and verify StatusBarDatetime > InitialDatetime.
I thought I'd found a few clues here and there so have tried various ideas including
const todaysDate = Cypress.moment().format('MMM DD, YYYY')
and saving as a variable, or
timestamp = Cypress.moment().utc();
cy.log('${timestamp}')
but Cypress.moment seems to throw an error (I might be using it incorrectly, or even in the wrong place) and I don't feel I'm getting any closer. I'm very new to this stuff so apologies if there is an obvious solution!
thanks,
Paul
Beta Was this translation helpful? Give feedback.
All reactions