Run cypress test without using the GUI - cypress

Is it possible to run a Cypress test without using the GUI where you can choose the test file. Currently I open it this way:
I type in CMD: node_modules/.bin/cypress open and then the GUI pops up where I can choose my test.
Is there a command which avoids that the GUI is popping up and what is the command?

You can run with command line in headed like this:
node_modules\\.bin\\cypress run --headed
this will run the tests by default in Electron browser.
And headless:
node_modules\\.bin\\cypress run

Yes, it is cypress run. It is all described in the documentation.
To run a specific file, you need to pass --spec argument, like this:
node_modules/.bin/cypress run --spec "cypress/integration/nameOfTheTest.js"

Related

Cypress run some of tests in parallel

I have done lot of research of running some tests in parallel and some in series. Still, not have any great options for doing that. We'll have 4 virtual machines to done this. All tose vm's has own docker for application with own database as well. I have few tests which need to be run at the same machine.
I'll thinking can there be given some tags or something which can be configured so that spesified tags will run on VM 1 example?
Found solution by plugin named Cypress grep, link is below. With it you can write tags to tests like this:
it('works', { tags: '#smoke' }, () => ...)
run all tests tagged #smoke
$ npx cypress run --env grepTags=#smoke
run all tests except tagged #smoke
$ npx cypress run --env grepTags=-#smoke
Install instructions and usage: https://www.npmjs.com/package/#cypress/grep
Work the way as the Robot Framework tags.

Cypress interface is not the same between open and run command

When I run cypress open here is the interface I get:
But if I run cypress run --browser chrome --headed --no-exit --spec cypress/e2e/test.cy.js the interface is not the same, I lose the button before the url (circled in red) and the url is not clickable.
Any idea how to get the same interface when I use cypress run ?

Cypress custom reporter problem with --spec flag

When I run tests via npx cypress run everything works fine, but when I want to run one or more tests via the --spec flag, I can't find this tests in the config and the reporter logic breaks, since the config doesn't changed testFiles field, if you specify the testFiles field in cypress.json or set it via the CLI npx cypress run --config testFiles='examp.spec.js' then everything works fine.
Here our cypress-reporter https://www.npmjs.com/package/#zebrunner/javascript-agent-cypress

Programmatically run cypress tests on docker

I am currently running cypress tests using:
await cypress.run({config inserted here})
Wondering if there is a way to spin up one of cypress's docker containers and then point the cypress tests there using the statement above. The suggestions online are to run the tests using command line, but I'm hoping to still be able to use cypress.run() and perhaps pass in an option that tells cypress to point the tests to a container?
Cypress docker containers will invoke cypress run by default. To change that, you'll need to override the container entrypoint to invoke node instead of cypress, and then pass your script file that's invoking cypress via the module api (cypress.run()) as the container command. You could do this via the command line, but it's a bit long because of all the options you'll need to pass:
# Assumes you're running this from the Cypress project directory on the host machine
$ docker run -it --rm -v $PWD:/tests -w /tests --entrypoint "/usr/local/bin/node" cypress/included:3.2.0 "myScript.js"
Warning: you're mounting in your npm dependencies with this method, which might cause problems if any of them were compiled on a different os like Windows.

Difference between Karma start and run Karma?

When I enter 'karma start' in the WebStorms' terminal, it opens Chrome and I can start testing, when I make some changes, it reruns the tests. But what is the difference when I type Karma start or when I click un Run Karma? Is Run Karma only for test reporters?
There are 2 console commands:
karma start
karma run
Karma start creates a karma server with the given config file and opens a browser window which connects to that server and waits for tests. You should use karma start after every change of your karma.conf.js file. The PhpStorm plugin does this automatically, by run it checks whether the config file is changed, and if so, it executes karma start before karma run.
Karma run sends your tests to the browser and runs them there. Your should use this after every change of your code or unit tests. Ofc the PhpStorm plugin does this automatically by every run.
The standard way is to run karma start and karma run as described by #inf3rno.
When running karma on CI/CD it's good to start karma, run the tests and exit. It's possible to reach using the singleRun: true option in the karma.conf.js. Check it out in the docs http://karma-runner.github.io/1.0/config/configuration-file.html.

Resources