diff --git a/e2e/cypress/support/e2e.js b/e2e/cypress/support/e2e.js index 15cecf637f8..374bdd84d93 100644 --- a/e2e/cypress/support/e2e.js +++ b/e2e/cypress/support/e2e.js @@ -7,9 +7,23 @@ Cypress.Screenshot.defaults({ const COMMAND_DELAY = 1000; -if (Cypress.env('SLOWMO')) { - const commandsToModify = ['clear', 'click', 'contains', 'reload', 'then', 'trigger', 'type', 'visit']; +function delay(ms) { + let now = Date.now(); + const end = now + ms; + do { + now = Date.now(); + } while (now < end); +} + +if (Cypress.env('SLOWMO')) { + Cypress.Commands.overwriteQuery('contains', function (contains, filter, text, userOptions = {}) { + delay(COMMAND_DELAY); + const call = contains.bind(this); + return call(filter, text, userOptions); + }); + + const commandsToModify = ['clear', 'click', 'reload', 'then', 'trigger', 'type', 'visit']; commandsToModify.forEach((command) => { // @ts-ignore -- https://github.com/cypress-io/cypress/issues/7807 Cypress.Commands.overwrite(command, (originalFn, ...args) => { @@ -65,3 +79,10 @@ beforeEach(() => { cy.setLocalStorage('grafana.featureToggles', toggles.join(',')); } }); + +afterEach(() => { + // in slowmo mode, wait to see the last command + if (Cypress.env('SLOWMO')) { + cy.wait(COMMAND_DELAY); + } +}); diff --git a/e2e/run-suite b/e2e/run-suite index ec9b5115ae4..a3d8d15913a 100755 --- a/e2e/run-suite +++ b/e2e/run-suite @@ -164,6 +164,8 @@ case "$1" in ;; "dev") echo "Dev mode" + # remove comment to run in slomo ( demo mode ) + # env[SLOWMO]=1 CMD="cypress open" enterpriseSuite=$(basename "${args[2]}") ;;