Cypress custom reporter problem with --spec flag - cypress

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

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.

Run cypress test without using the GUI

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"

Disable Logging test results at Cypress

I run my tests in the docker container and I would not want to see the logs about the results of the tests (since I run several instances of cypress and logs are mixed). Is there any way to turn off logging?
I have read documentation but i haven't found anything.
As per this github issue: https://github.com/cypress-io/cypress/issues/2071.
That issue was resolved at the 4.9.0 release of Cypress.
You can now run your Cypress tests with the --quiet flag. e g.:
cypress run --quiet

How do I send baseUrl as a parameter with Cypress.io

I am researching switching from Protractor to Cypress.io.
I have some tests up and running, however, I want to be able to send the baseUrl as a parameter as I can with Protractor.
I have tried:
$ npm run cypress:open --config "baseUrl=myUrl" --still uses the baseUrl from my config file.
$ npm run cypress:open --env "baseUrl=myUrl" --still uses the baseUrl from my config file.
and a host of other things, none of which work quite right.
I want to be able to pass a parameter to my command which gives me the flexibility to choose which environment I am running my tests in. I can do this with Protractor, with a command like this:
$ ng e2e --suite testSuite --baseUrl myUrl
What is the equivalent for Cypress.io?
You have to set the env variable CYPRESS_baseUrl
CYPRESS_baseUrl=[your baseUrl] npm run cypress:open should do it for you
I think the correct way to do this is:
$ npm run cypress:open -- --config "baseUrl=myUrl"
Otherwise, the config parameter is passed to npm instead of cypress. Notice the extra --
Good luck!
Brendan's answer is correct.
I would like to add that
$ npm run cypress:open --config "baseUrl=myUrl"
may not be working since you try to propagate some configuration into a command inside your package.json.
If instead you'd do for example:
$ ./node_modules/.bin/cypress run --config baseUrl=myUrl
it should work just fine.
This is good to know since it will let you use additional CLI options as well (which you do not know ahead of time).
PS: --env wouldn't work for baseUrl since baseUrl is a built-in configuration value and not a regular env variable.
What I did was simply:
export CYPRESS_BASE_URL=SOME_OTHER_URL
yarn cypress run
This will override the baseUrl configuration. See: https://docs.cypress.io/guides/guides/environment-variables.html#Overriding-Configuration

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