cypress: `pause()` should not be ignored with `cypress run --headed --no-exit`

Current behavior:

cy.pause() is ignored when specs are run with cypress run

image

Notice that I have cy.pause() in the code to the left, but the test on the run hasn’t paused

Desired behavior:

I’d want the test to actually pause. Or make it really clear in the documentation that pause() is only working when you use cypress open

This is what it looks like when I use cypress open. I want the same behavior when I run with cypress run

image

Steps to reproduce: (app code and test code)

Add cy.pause() to any test, run it with cypress run, observe that the test is not paused.

Versions

Win 10 Electron (included with cypress) Cypress 3.2.0

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 11
  • Comments: 30 (11 by maintainers)

Most upvoted comments

Yeah, this does seem like a valid use case though, I believe the cy.pause() should work as normal when running with --headed --no-exit flags.

My use case is that I need to debug why a test is failing only in cypress run and not cypress open. I tried the solution offered by @Konstruktour but cypress run apparently doesn’t take that config option anymore.

My workaround was to overwrite cy.pause() when using the CLI:

cypress/support/commands.js

Cypress.Commands.overwrite('pause', (originalFn, subject, options) => {
  if (Cypress.config('isInteractive')) {
    return originalFn(options)
  } else {
    cy.task('pause')
  }
});

cypress/plugins/index.js

const readline = require("readline");
module.exports = (on) => {
  on('task', {
    pause() {
      const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
      });
      return new Promise((resolve) => {
        rl.question("Press [Enter] to continue", (answer) => {
          console.log(answer)
          rl.close()
          return resolve(answer);
        })
      });
    }
  });
}

as a workaround: set the config parameter Cypress.config('isInteractive', true); , then pause works like in the headed mode.

My use-case for this is to be able to tell someone:

You can reproduce the issue by doing git fetch origin my-debugging-branch git checkout my-debugging-branch bundle exec rails server -p 3000 # Then in a separate terminal yarn cypress run --no-exit --headed --spec=cypress/integration/bugs/reproduce_bug.spec.js

If I can have a single test pause at meaningful points with comments, then I can use cypress as a walkthrough of a problem. If I can specify the test path on the command line and have cypress immediately start running it, then someone who isn’t yet sold on cypress does not have to hunt around the interface for the test that I point to, but can instead just run that command and see “woah, this is animating the browser in front of me and not flakey” just after copy-pasting commands.

This turns cypress into a tool for

  • Communicating about bugs
  • Getting myself or someone else set up to debug a problem on either client and server Allowing Cypress to demonstrate its value to new people.

My use-case might be better accomplished by adding a --spec argument to cypress open which would cause a particular test or set of tests to run immediately upon opening. Then I could do cypress open --detached --spec=cypress/integration/bugs/reproduce_bug.spec.js

+1, in nrwl/nx environment, “cypress run” is the default command

Because of this issue #1669. I cannot use cypress open to run my case. So I need cy.pause() to work on cypress run