All Projects β†’ codica2 β†’ cypress-best-practices

codica2 / cypress-best-practices

Licence: other
How we test frontend applications

Projects that are alternatives of or similar to cypress-best-practices

awesome-cypress
πŸŽ‰ A curated list of awesome things related to Cypress
Stars: ✭ 274 (+1422.22%)
Mutual labels:  cypress-io
cypress-browserify-preprocessor
Cypress preprocessor for bundling JavaScript via browserify
Stars: ✭ 23 (+27.78%)
Mutual labels:  cypress-io
cypress-angularjs-unit-test
Unit test Angularjs code using Cypress.io test runner
Stars: ✭ 23 (+27.78%)
Mutual labels:  cypress-io
snapshot
Adds value / object / DOM element snapshot testing support to Cypress test runner
Stars: ✭ 114 (+533.33%)
Mutual labels:  cypress-io
TLE5012-Magnetic-Angle-Sensor
This repository includes an library for Arduino for the TLE5012 Magnetic Angle Sensor with SSC interface.
Stars: ✭ 37 (+105.56%)
Mutual labels:  cypress-io
cypress-get-it
Get elements by data attribute by creating a Cy command on the fly
Stars: ✭ 23 (+27.78%)
Mutual labels:  cypress-io
cypress-xpath
Adds XPath command to Cypress test runner
Stars: ✭ 145 (+705.56%)
Mutual labels:  cypress-io
next-and-cypress-example
Next.js example instrumented for code coverage from Cypress tests
Stars: ✭ 111 (+516.67%)
Mutual labels:  cypress-io
cypress-upload-file-post-form
Solution for two Cypress testing use-cases I came across with: perform a direct http FORM request to the server containing a file and other parameters and upload a file into a form before submission
Stars: ✭ 59 (+227.78%)
Mutual labels:  cypress-io
cypress-example-circleci-orb
Demo of using the Cypress CircleCI Orb
Stars: ✭ 26 (+44.44%)
Mutual labels:  cypress-io
cypress-retry
Retry just the failed Cypress.io tests using Cypress module API and AST rewriting
Stars: ✭ 16 (-11.11%)
Mutual labels:  cypress-io
fd-cypress-recorder
Browser plugin Fd Cypress Recorder captures user interactions and generates Cypress test code.
Stars: ✭ 25 (+38.89%)
Mutual labels:  cypress-io
instrument-cra
Little module for CRA applications to instrument code without ejecting react-scripts
Stars: ✭ 61 (+238.89%)
Mutual labels:  cypress-io
cypress-hyperapp-unit-test
Unit test Hyperapp components using Cypress
Stars: ✭ 26 (+44.44%)
Mutual labels:  cypress-io
vite-ts-tailwind-starter
Opinionated Vite + Vue 3 + TypeScript + Tailwind CSS starter template w/ tests and CI.
Stars: ✭ 228 (+1166.67%)
Mutual labels:  cypress-io
blog
Personal blog, open sourced; get a peek to what I'm up to. Fix my typos and my poor english.
Stars: ✭ 27 (+50%)
Mutual labels:  cypress-io
cypress-test-tiny
Tiny Cypress E2E test case
Stars: ✭ 48 (+166.67%)
Mutual labels:  cypress-io
cypress-example-docker-compose
Example running Cypress tests against Apache server via docker-compose
Stars: ✭ 106 (+488.89%)
Mutual labels:  cypress-io
todo-graphql-example
Example Todo app on top of json-graphql-server
Stars: ✭ 20 (+11.11%)
Mutual labels:  cypress-io
cypress-watch-and-reload
Reloads Cypress when one of the watched files changes
Stars: ✭ 46 (+155.56%)
Mutual labels:  cypress-io

Testing frontend applications with Cypress

Cypress is an all-in-one testing framework, assertion library, with mocking and stubbing, all without Selenium.

Cypress installation

Cypress is realy easy to install, just use your package manager: npm

npm install cypress --save-dev

or yarn:

yarn add -D cypress

Running Cypress

After Cypress installation you can call it from your project root:

./node_modules/.bin/cypress open

While there’s nothing wrong with writing out the full path to the Cypress executable each time, it’s much easier and clearer to add Cypress commands to the scripts field in your package.json file.

{
  "scripts": {
    "cypress:open": "cypress open"
  }
}

Now you can call cypress via:

npm run cypress:open

Setting up CI

Configure Cypress in CI is almost the same as running it locally. You generally only need to do two things:

  • Install Cypress
npm install cypress --save-dev
  • Run cypress
cypress run

Feature tests examples

Cypress uses pretty simple DSL for writing tests

describe("Home", () => {

  beforeEach(() => {
    cy.visit("/");
    cy.get("input").first().type("[email protected]");
    cy.get("input").last().type("password");
    cy.server();
  });

  it("Should login with email and password", () => {
    cy.route("POST", "/api/v1/admin/user_token", "fixture:login.json");
    cy.route("GET", "/api/v1/admin/contacts", "fixture:contacts.json");
    cy.get("button").click();
    cy.url().should("include", "/contacts");
  });

  it("Should not login ", () => {
    cy.route("POST", "/api/v1/admin/user_token");
    cy.get("button").click();
    cy.get(".notices").contains("Invalid login or password");
    cy.url().should("include", "/login");
  });
});

More examples

Fixtures examples

Fixtures load a fixed set of data located in a file. It is very useful if you want to stub server response. For example, after login we need to include access token in the server response, we will create a file:

fixtures/login.json

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdwpMeJf36POk6yJV_adQssw5c"
}

Or return users data after GET request to /users page

fixtures/users.json

{ 
  "data": [
    { "id": 1, "attributes": { "name": "John", "email": "[email protected]", "id": 1 } },
    { "id": 2, "attributes": { "name": "Ned", "email": "[email protected]", "id": 2  } }
  ]
}

License

Copyright Β© 2015-2019 Codica. It is released under the MIT License.

About Codica

Codica logo

We love open source software! See our other projects or hire us to design, develop, and grow your product.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].