cypress-io / cypress

Fast, easy and reliable testing for anything that runs in a browser.
https://cypress.io
MIT License
46.72k stars 3.16k forks source link

Expose command timing #9263

Open bahmutov opened 3 years ago

bahmutov commented 3 years ago

What would you like?

I would like to know how long every command took to execute during the test to figure out how to speed things up. Was it the cy.visit? Or cy.request? Or cy.get('selector').should('be.visible')?

We do have this information already - read https://www.cypress.io/blog/2020/05/22/where-does-the-test-spend-its-time/ and could provide it to the user either on demand, or by default

As the first step, I think we could simply add command timing to the DevTools Console output when clicking on the command

Screen Shot 2020-11-20 at 12 16 16 PM

We already report duration for some commands, like cy.request, but could report it for all of them.

Second step would show those durations for every command in the reporter, like this

Screen Shot 2020-11-20 at 12 23 23 PM

Why is this needed?

People complain about Cypress being slow - https://twitter.com/sunpietro/status/1329545832262152203 is one example, and the first step to answering this question is understanding where the test is spending its time.

ayshiff commented 3 years ago

@bahmutov Can I work on this ? 👍

bahmutov commented 3 years ago

Sure, start with something simple like printing the command duration when clicked

bahmutov commented 3 years ago

For command log properties, we could use log:changed event https://on.cypress.io/catalog-of-events to add duration to every command

Cypress.on('log:changed', options => {
  if (options.instrument === 'command' && options.consoleProps) {
    options.wallClockStoppedAt = Date.now()
    options.duration = +options.wallClockStoppedAt - (+ new Date(options.wallClockStartedAt))
    options.consoleProps.Duration = options.duration
  }
})
Screen Shot 2020-12-04 at 9 36 48 AM
bahmutov commented 3 years ago

Made my code into a tiny plugin https://github.com/bahmutov/cypress-timings and wrote a blog post https://glebbahmutov.com/blog/cypress-timings/

ayshiff commented 3 years ago

@bahmutov Do I have to close my Draft PR then ?

bahmutov commented 3 years ago

No, let it stay @ayshiff - no harm, and we are thinking about how to better grab those numbers and how to show them in the GUI

AndreyYevtukhov commented 1 year ago

Any updates on this? :)