How to run Cypress component tests in CI - cypress

I've just started using Component tests (Svelte) and they run in the Cypress GUI without problem. Now I want to put them in CI, but when I use run mode only the e2e tests are running.
What I've tried:
yarn cypress run
npx cypress run

You can pass the --component flag on the command line to run component tests:
yarn cypress run --component

Related

browser not launched while running from terminal using cypress

I am running the below command from terminal.
npx cypress run --browser chrome --spec "cypress/integration/SmokeTests/CreateDepartment.ts"
The application is not launched in chrome browser instead runs in headless mode. I haven't included --headless in the above command. Any idea why this command runs the tests in headless mode?
By default, Cypress will run tests headlessly during cypress run.
Source

Cypress not launching chrome browser after "npx cypress run --browser chrome" command

I want to run tests serially (one after another) for that I used command npx cypress run --browser chrome but it is running headless in terminal I see this
From what I see in Udmey videos while I was learning it executes all the tests or .js files one after another in chrome browser
I'm currently using "cypress": "^9.5.1",
I tried with full path as well
npx cypress run --browser C:\Program/Files\Google\Chrome\Application\chrome.exe
I give me
I tried with full path as well
npx cypress open --browser chrome
It just open the Cypress window with test names to select.
Is there a way to run all the tests one after another automatically with chrome browser open.
Sorry for if use bad english grammar
With npx cypress open you get a button to run all tests.
Make sure you have the Chrome browser selected (above the "Run 38 integration specs" button)
You should also understand that npx cypress run --browser chrome is also running all the test in chrome.
Headless means you don't see the browser, only messages in the terminal. But Cypress tests always run in the browser.

Cypress dependency issues in Docker container

I am trying to integrate cypress to the bitbucket pipeline. And I am following the official documentation:
- step:
script:
# install dependencies
- npm ci
# run Cypress tests
- npm run e2e (env variables here)
I launch the container locally as follows:
docker run -v `pwd`:/mycode -it imagename /bin/sh
cd /mycode
and I run the steps in the script:
/mycode# npm ci; npm run e2e (env variables here)
But I get the following error:
/root/.cache/Cypress/8.2.0/Cypress/Cypress: error while loading shared libraries: libgbm.so.1: cannot open shared object file: No such file or directory
I ran apt-get install xvfb libgtk2.0-0 libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2, as per documentation when I got libgtk2.0-0 missing dependency and it threw the next one.
I also have added :nvm install "lts/*" --reinstall-packages-from="$(nvm current)" as a step to update node to the latest version and match cypress requirements,
but is there any general practice on how to integrate cypress in an existing project's pipeline and to work around these library issues?
Is the fix just to install the library or is there a better integration practice and something I'm missing?
You can actually use an official cypress image only for the step where you want to run the tests. You can choose the version which suits you the best.
- step:
name: run tests
image: cypress/browsers:node12.18.3-chrome87-ff82
script:
# install dependencies
- npm ci
# run Cypress tests
- npm run e2e (env variables here)

cypress download: "cypress run" appears to be the same as "cypress open"

I'm using the zip file download of Cypress as the server it's running on can't access npm.
I've added the following to the scripts section pf package.json
"cy:cypress": "D:/Cypress/cypress.exe",
"cy:open": "D:/Cypress/cypress.exe open",
"cy:run": "D:/Cypress/cypress.exe run",
All of them generate the page show in the image below, which I believe is the dashboard.
My understanding is that the third of these runs the tests headlessly.
It's almost like 'open' and 'run' are ignored in the 2nd and 3rd script so in reality thay are all calls to cypress.exe.
Is this expected behaviour?
Can the download version of Cypress 'run' tests?
if so how?
Thanks
You are trying to execute cypress executable here, which won't work, you have to use cypress command which is installed globally or execute it from your node_modules, so here are the two ways -
npx cypress open
node_modules\.bin\cypress open
cypress open - this will work if you have cypress installed globally and cypress command is part of your operating system's environment variables
You can replace the command open with run preferably if you want to run it in headless mode by using --headless option which means it will not open the runner and it will just run the tests in the terminal.
Slightly unrelated, but you can also use --spec to specifically run a particular test and --browser chrome to run it on a specified browser e.g. chrome in this command
npx cypress run
open cmd where you cypress file exist the run the above command it will run headless without UI

Percy - Cypress - Error: Could not find browser revision 756035. Run "npm install" or "yarn install" to download a browser binary

Im trying to set up a simple visual test with cypress and Percy.
Following the tutorial I installed percy as part of my cypress package, however when I attempt to run.
npx percy exec -- cypress run. I am met with the message:
Error: Could not find browser revision 756035. Run "npm install" or "yarn install" to download a browser binary.
Anyone else had this issue?
May be worth noting, when I run npx cypress run, the tests run as expected.
Something went wrong with npm install process, most likely the decompress failed which does not return a error.
Easiest way is to remove node_modules and install again.

Resources