bahmutov / cypress-time-marks

Custom Cypress commands to measure elapsed time

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

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

About

Custom Cypress commands to measure elapsed time


Languages

Language:JavaScript 66.6%Language:TypeScript 33.4%