--
JanisRancourt - 15 Sep 2020
Cypress Introduction
About
Cypress is a framework tool used for creating and running TCs using a programming language. Mostly used for testing front-end web apps. It runs in the browser itself (Chrome only) and doesn't need extra tools like Selenium
WebDriver. It uses the browser to search the DOM.
It can be used alongside Mocha and Applitools.
Pros of using Cypress
- Lightweight and fast (runs tests in minutes)
- Can easily mock server responses
- Simpler and cleaner code than Selenium WebDriver
Cons of using Cypress
Installation
You can install Cypress with the following command via npm:
npm install -D cypress
This will install it in your project as a developer dependency, as indicated by the -D flag. You can also replace "install" with "i" as a shorthand, and it will work the same way.
This downloads the desktop application as well as the CLI.
You can open the desktop application with this command:
npx cypress open
When testing your application, the app will be shown on the right, while the actions of the test will be shown on the left.
To use Cypress commands, you can call the API by preceding commands with "cy.", for example "cy.get()" or "cy.request()".
Visit a webpage by using "cy.visit()".
cy.visit('https://example.com/')
You can get elements by targeting them with their CSS selectors.
cy.get('img.logo')
This will target an image with the class of "logo" within the page.
Further information can be found on the official website for Cypress, found at
https://cypress.io.