1.6.0 • Published 3 months ago

cypress-time-marks v1.6.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 months ago

cypress-time-marks cypress version

Custom Cypress commands to measure elapsed time

cy.timeMark('start').wait(1500).timeSince('start').wait(500).timeSince('start')

Time marks

See spec.cy.js

Install

Add this plugin as a dev dependency

# if using NPM
$ npm i -D cypress-time-marks
# if using Yarn
$ yarn add -D cypress-time-marks

Import this plugin from the spec file or from the support file

// cypress/e2e/spec.cy.js or cypress/support/e2e.js
import 'cypress-time-marks'

This should give you two new custom commands cy.timeMark(name) and cy.timeSince(name). If you want TypeScript definitions, this module includes them:

// my spec JS file
/// <reference types="cypress-time-marks" />

Options

cy.timeSince(markName: string, label?: string, timeLimit?: number, throwError?: boolean)

labels

You can log a label when using cy.timeSince(name, label)

cy.timeMark('start')
  .wait(1500)
  .timeSince('start', 'initial wait')
  .wait(500)
  .timeSince('start', 'final load')

Time marks with labels

time limit warning

You can pass a time limit after the mark name to warn if the elapsed time is longer than the limit. It won't fail the test, but it will change the icon to warn you.

cy.timeMark('start')
  .wait(100)
  .timeSince('start', 'under time limit', 200)
  .wait(500)
  .timeSince('start', 'over time limit', 200)
  .timeSince('start', 200)

Time limit warnings

fail the test

You can fail the test if the elapsed time is above the given limit.

cy.timeMark('start').wait(100).timeSince(
  'start', // mark name
  'waiting', // message
  50, // time limit (ms)
  true, // throw an error if above the time limit
)

Failing test because of the time limit

timeBetween

Sometimes you want to measure time, but assert the durations after the fact.

// run commands and capture the marks
cy.timeMark('start').wait(400).timeMark('finish')
// confirm the durations between two marks
cy.timeBetween('start', 'finish')

You can add a label, set maximum duration, and even throw an error if the duration is above the given limit.

// label this duration "loading time" in the command log
// and if it exceeds 1 second, throw an error failing the test
cy.timeBetween('start', 'finish', 'loading time', 1000, true)

See also

Small print

Author: Gleb Bahmutov <gleb.bahmutov@gmail.com> © 2022

License: MIT - do anything with the code, but don't blame me if it does not work.

Support: if you find any problems with this module, email / tweet / open issue on Github

1.6.0

3 months ago

1.5.0

3 months ago

1.4.0

1 year ago

1.3.1

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago