Coder Social home page Coder Social logo

cypress-end-to-end-testing's Introduction

W08D04 - End-to-End Testing with Cypress

To Do

  • Jest vs Cypress
  • Install and Configure Cypress
  • Design End-to-End Tests with Cypress

Jest vs Cypress

  • Jest
    • Command line test runner
    • Based around testing assertions
    • Used for unit and integration testing (mostly)
  • Cypress
    • Runs its own browser to execute the tests in
    • Performs operations and interacts with the site the way that a user would (eg. typing into input fields, clicking on buttons)
    • Used for integration and E2E testing (mostly)

Install and Configure Cypress

  • Cypress can be installed locally to the project (as a dev dependency) or globally on your OS
npm install -g [email protected]
npm install --save-dev [email protected]
  • Use the open command to start Cypress running
# global installation
cypress open

# local installation
node_modules/.bin/cypress open
  • Add a script to package.json for a quick way to start Cypress
"cypress": "node_modules/.bin/cypress open"
npm run cypress
  • We use the cypress.json file in the main directory to configure Cypress
{
  "baseUrl": "http://localhost:3000",
  "viewportWidth": 1280,
  "viewportHeight": 1200
}
  • baseUrl tells Cypress where our application is hosted and what port it's listening on
  • viewportWidth and viewportHeight specify the dimensions for Cypress' browser to use
  • Feel free to change the width and height values if developing for a mobile-first site

Folders/Files and their Purposes!

  • /cypress.json: Used to override default configuration values.
  • /cypress/fixtures: Test data; often in JSON.
  • /cypress/integration: Our test specifications.
  • /cypress/plugins: Add-ons to expand on Cypress' functionality.
  • /cypress/support: Scripts; an area where we can add on to Cypress if needed.

Common Commands

  • describe(), it(), and beforeEach() are afforded to us by Mocha.
    • Describe is used to, well, describe a block of tests!
    • It is used to label a specific test block / unit.
    • BeforeEach allows us an opportunity to add code/setup that will run before each text in the block.
  • cy.visit() visits a web page.
  • cy.get() Retrieves an HTML element based on jQuery/CSS-like selectors.
    • .as() Assign an alias for later use in cy.get() or cy.wait(), use an @ in a selector to call upon an alias.
  • .find() Retrieves a child element from inside of a selected element.
  • cy.intercept() Used for "spying" (checking for use of a particular request) or "stubbing" (replacing the response for a particular request.)
  • cy.wait() Waits before proceding with test instructions.
  • .click(), .type(), .check() are used to interact with elements and forms in a web page.

Resources

cypress-end-to-end-testing's People

Contributors

masavi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.