Cypress is a next-generation front-end testing tool built for the modern web that greatly improves your testing experience. It is built on Mocha, which is a feature-rich JavaScript test framework running on and in the browser, making asynchronous testing simple and fun. Cypress addresses the key pain points developers and QA engineers face when testing modern applications.
Cypress helps you:
Cypress is most often compared to Selenium. However, Cypress is both fundamentally and architecturally different when compared to Selenium. Cypress is not constrained by the same restrictions as Selenium. This enables you to write faster, easier and more reliable tests.
Cypress is completely configured for operation and comes with a set of batteries as well. Here is a list of features that no other testing frameworks have
Cypress is a next-generation front-end testing tool built for the modern web that greatly improves your testing experience. It is built on Mocha, which is a feature-rich JavaScript test framework running on and in the browser, making asynchronous testing simple and fun. Cypress addresses the key pain points developers and QA engineers face when testing modern applications.
Begin by creating a new folder
Installing Cypress can take around 2 to 3 minutes, based on your network speed.
NPM
Installing Cypress is a fairly easy task:
YARN
The first command will create a package.json file and the second command will install cypress as a devDependencies array in your package descriptor (package.json) file.
Cypress has now been installed in your ./node_modules directory.
To Open Cypress:
If you used npm to install, Cypress has now been installed to your ./node_modules directory, with its binary executable accessible from ./node_modules/.bin.
Now you can open Cypress from your project root one of the following ways:
The long way with the full path
Or with the shortcut using npm bin
Or by using npx (note: npx is included with npm > v5.2 or can be installed separately.)
Or by using yarn
After a moment, the Cypress Test Runner will launch. Cypress will start for the first time and a bunch of new folders will appear in your project.
This also pops up a window that looks like this:
According to the header text, it has added test samples. Let's have a look at our project structure:
We see that we have a directory called cypress containing an integration subfolder as:
Looking at the content of the examples folder we can see that it contains everything we could possibly want to know how to do such as:
and much much more.
Let’s Create Your First Test!
Let’s create a new file sample.spec.js under the cypress/integration folder:
This high-level approach looks like:
Let's add the following content to sample_spec.js:
Once you save this file you can see:
Click on sample.spec.js file, it will open the test runner
As we can see it is able to correctly assert on the URL as well as the element.
Things you should know about Cypress before adopting:
Cypress screenshots and seeing how the progress of your test is a marvelous way to debug the tests, and a marvelous way to start to understand why the test failed. The whole experience helps in writing, understanding, and debugging tests, and in analyzing their results. It works as expected and makes our lives a lot easier!
This is not an end there are more features that Cypress provides, stay tuned for more blogs around Cypress!