Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cypress - automatically run all tests in browser, with hot reload

Tags:

cypress

By default, running cypress open opens the Cypress window and then I have to manually hit the "Run All Tests" button to run them all.

How can run all tests in the browser just by running the cypress open, with no additional step?

Thank you.

Edit: I need the tests to rerun when I change the test files, just like cypress open does, so just running them once (like in headless mode) doesn't help.

like image 957
claudiut Avatar asked Apr 04 '18 08:04

claudiut


2 Answers

When using cypress open you can get tests to rerun in the browser after each edit by using the global configuration option watchForFileChanges as detailed here

You can pass this as a command line argument:

cypress open --config watchForFileChanges=true

Or you can specify it in your cypress.json file:

{
    "watchForFileChanges": true
}

You will still need to click run all specs when you first run cypress open, but after that any edit to the test files will cause the tests to be rerun.

like image 67
Craig Avatar answered Sep 22 '22 14:09

Craig


If you run Cypress tests headlessly cypress run it runs all tests without the need to click the "Run all tests" button.

I've found using npx cypress run is the best way to do this. The documentation on running cypress headlessly specifies additional options you can use: https://docs.cypress.io/guides/guides/command-line.html#

like image 23
red_dorian Avatar answered Sep 25 '22 14:09

red_dorian