Giter Site home page Giter Site logo

cypress-io / testing-workshop-cypress Goto Github PK

View Code? Open in Web Editor NEW
475.0 475.0 189.0 46.16 MB

End-to-end testing workshop with Cypress

Home Page: https://testing-workshop-cypress.netlify.app/

JavaScript 97.36% HTML 2.52% CSS 0.02% TypeScript 0.10%
cypress cypress-io testing workshop

testing-workshop-cypress's Introduction

testing-workshop-cypress

cypress version CircleCI Build status renovate-app badge

A full day testing workshop complete with application, exercise tests and speaker slides for Cypress.io

Requirements

In order to get the code and install dependencies

git clone [email protected]:cypress-io/testing-workshop-cypress.git
cd testing-workshop-cypress
npm install

If necessary, install dependencies inside TodoMVC folder

cd todomvc
npm install

Quick check โœ…

You can test the installation by starting TodoMVC in the first terminal window

cd todomvc
npm start

and you should see in the terminal

> json-server --static . data.json --middlewares ./node_modules/json-server-reset


  \{^_^}/ hi!

  Loading data.json
  Loading ./node_modules/json-server-reset
  Done

  Resources
  http://localhost:3000/todos

  Home
  http://localhost:3000

Note for Windows users: if npm start throws an error, it is probably due to cd todomvc; ... first command in the npm start script. In this case change the working folder to "todomvc" and run npm start from there.

From the second terminal window you should be able to open Cypress in the root of the project with

$ npm run cy:open

> [email protected] cy:open /git/testing-workshop-cypress
> cypress open

Tip

You can use the installed start-server-and-test utility to start the app, open Cypress and then shutdown the app when you exit Cypress.

$ npm run dev

Application ๐Ÿ’พ

Vue.js + Vuex + REST server application that we are going to test is in the folder todomvc. This application and its full testing is described in this blog post. The application should run fine without network access.

Slides ๐Ÿ–ฅ

See the presentation at https://testing-workshop-cypress.netlify.app/. Every section of the presentation has a subfolder in the slides folder with a Markdown file. The Markdown is rendered into HTML using Vite and Reveal.js combination. You can open the presentation by clicking on "link" in the table below.

Content ๐Ÿ—‚

Beginner

topic folder contents slides
๐Ÿ”— Introduction, TodoMVC application todomvc intro.md link
๐Ÿ”— Loading page 00-start 00-start link
๐Ÿ”— cypress open vs cypress run 01-basic 01-basic link
๐Ÿ”— Adding items test, cypress.json file 02-adding-items 02-adding-items link
๐Ÿ”— Selector Playground 03-selector-playground 03-selector-playground link
๐Ÿ”— Reset database using cy.request 04-reset-state 04-reset-state link
๐Ÿ”— Spy and stub XHR requests, fixtures 05-xhr 05-xhr link
๐Ÿ”— Access application code and data 06-app-data-store 06-app-data-store link

Intermediate

topic folder contents slides
๐Ÿ”— Setting up E2E tests on CI 07-ci 07-ci link
๐Ÿ”— Setting up Cypress Dashboard 07-ci 08-dashboard link
๐Ÿ”— Test reporters - 09-reporters link
๐Ÿ”— Configuration - 10-configuration link
๐Ÿ”— Retry-ability 11-retry-ability 11-retry-ability link
๐Ÿ”— Custom commands 12-custom-commands 12-custom-commands link

Advanced

topic folder contents slides
๐Ÿ”— Page Objects vs App Actions 13-app-actions 13-app-actions link
๐Ÿ”— Fixtures 14-fixtures 14-fixtures link
๐Ÿ”— Debugging 02-adding-items/demo.js 15-debugging link
๐Ÿ”— Preprocessors 16-preprocessors 16-preprocessors link
๐Ÿ”— Component testing 17-component-testing 17-component-testing link
๐Ÿ”— Backend code 18-backend 18-backend link
๐Ÿ”— Code coverage 19-code-coverage 19-code-coverage link
๐Ÿ”— Stubbing methods 20-stubbing 20-stubbing link
The end - end link

For speakers ๐ŸŽ™

Netlify Status

This workshop can take all day, but you can pick the sections you are interested in teaching at will and customize it into any time duration. Everyone is coding for the most part, except for CI and the Cypress Dashboard sections, where the usage was shown via slides and actual sites.

During the workshop, keep the todomvc app running in one shell, while each section 01-basic, 02-..., 03-... etc. has its own Cypress and specs subfolders cypress/integration/.... Usually a spec has several tests with placeholder comments. The workshop attendees are expected to make the tests pass using the knowledge from the slides and hints (and Cypress documentation). Note that most folders have a prepared spec.js file and an answer.js file. The answer.js file is ignored by Cypress using a setting in cypress.json.

The only exception is the folder 00-start. This is a folder for students to see how Cypress scaffolds example specs when you open Cypress for the very first time. In this folder students should execute...

cd 00-start
npm run cy:open

...and see the list of created example specs.

The slides are generated using Reveal.js from Markdown sources in the slides folder. You can show the slides locally by running

npm run slides:dev

The slides are deployed to Netlify automatically, see https://testing-workshop-cypress.netlify.app/

Additional information ๐Ÿ—ƒ

testing-workshop-cypress's People

Contributors

amirrustam avatar bahmutov avatar bartduisters avatar dbeigi avatar jennifer-shehane avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

testing-workshop-cypress's Issues

Add section about reporters

  • how to use Mocha's built-in reporters
  • how to use mocha awesome reporters
  • combine multiple reports into one using a separate tool

Add large application assignment

Users from the workshop expressed a desire to include a larger application as a test case and let them figure out how to test it. This would include planning tests, writing them, etc. Probably would be 1-2 hour activity.

can we use correct relative paths in slides?

Currently slides are included from the root pitchme.md file and all image paths are relative. But when GitHub shows each markdown file in slides folder the image links are broken. Maybe there is a way to specify folder for relative paths to have images appear in github and in gitpitch correctly

Find a better local presentation workflow

Currently we cannot see local slide presentation preview without jumping through lots of hoops. Maybe it would be better to switch from Gitpitch to something friendlier

Ideas

Full day Cypress workshop ideas

first half - same as before

second half - new content

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Rate-Limited

These updates are currently rate-limited. Click on a checkbox below to force their creation now.

  • Update dependency @cypress/browserify-preprocessor to v3.0.2
  • Update dependency cypress-xpath to v1.8.0
  • Update dependency eslint-plugin-cypress to v2.12.1
  • Update cypress orb to v2
  • Update cypress/base Docker tag to v18
  • Update dependency cypress to v11
  • Update dependency cypress-xpath to v2
  • ๐Ÿ” Create all rate-limited PRs at once ๐Ÿ”

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

circleci
.circleci/config.yml
  • cypress 1.28.0
  • cypress/base 12.14.0
  • cypress/base 12.14.0
  • cypress/base 12.14.0
  • cypress/base 12.14.0
  • cypress/base 12.14.0
github-actions
.github/workflows/main.yml
  • cypress-io/github-action v2
  • cypress-io/github-action v2
.github/workflows/min-node-version.yml
  • cypress-io/github-action v2
  • cypress/base 12.0.0-libgbm
.github/workflows/windows.yml
  • cypress-io/github-action v2
npm
00-start/package.json
package.json
  • @cypress/browserify-preprocessor 3.0.1
  • @cypress/code-coverage 1.14.0
  • cypress 7.6.0
  • cypress-dark 1.7.14
  • cypress-failed-log 2.9.1
  • cypress-pipe 1.7.0
  • cypress-plugin-snapshots 1.4.4
  • cypress-react-unit-test 2.10.0
  • cypress-xpath 1.6.2
  • eslint-plugin-cypress 2.11.3
  • start-server-and-test 1.12.1
  • typescript 4.3.4
todomvc-redux/package.json
  • start-server-and-test 1.12.1
todomvc/package.json

  • Check this box to trigger a request for Renovate to run again on this repository

Add section on configuration

How to set Cypress config variables: cypress.json, cypress.env.json, command line, environment variables, in code

note: this might change in the future versions of Cypress.

test on Windows

Probably on AppVeyor CI to confirm that paths are all working for Windows users

Add CLA

because outside users are submitting pull requests

TDD approach in workshop tests: make them fail by default

@bahmutov About the discussion we add on Full day Cypress workshop, here is what I would suggest so that workshop tests fail by default, which I find is a better TDD approach:

// create a specific command for failures
Cypress.Commands.add("fail", description => {
  throw new Error(description);
});

// in .spec.js files 
it('starts with zero items (stubbed response)', () => {
  cy.fail('start Cypress network server')
  cy.fail(`stub 'GET /todos' with []
    save the stub as an alias`)

  // THEN visit the page
  cy.visit('/')

  cy.fail(`wait for the route alias
    grab its response body
    and make sure the body is an empty list`)
})

The trainee will be reminded step-by-step what he has to do.
I am not sure about the multi-fail approach, which could make him think he didn't do the expected thing he just jumped to the next fail ; any remark about it ?

Tell me If you consider it's a good idea, so that I extend it to all tests and make a PR.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Preset name not found within published preset config (monorepo:babel6). Note: this is a nested preset so please contact the preset author if you are unable to fix it yourself.

Consider merging example applications

We have 3 TodoMVC applications

  • Vue + Vuex + REST api without bundling used for most of the workshop
  • TodoMVC React with bundling for showing testing components
  • TodoMVC Redux for showing code coverage

We could just update the main Vue application and use it for everything

  • split into components, bundle using parcel-json-server to serve the app and have the REST api (@amirrustam )
  • use cypress-vue-unit-test to demo component testing (@amirrustam )
  • measure code coverage(@bahmutov )

Make sure all answers pass

Using command

npx cypress run --spec 'cypress/integration/*/answer.js' \
 --config ignoreTestFiles="",supportFile=cypress/support/reset.js

Currently only the following pass / fail

Screen Shot 2019-10-28 at 7 48 42 AM

Consider paying for GitPitch

Since my promotional GitPitch Pro subscription expired after 1 year, each slide deck shows a last slide asking to pay. We could transition to something else for showing slides, or just pay for the GitPitch Pro license.

suggestion: move lesson 4 up

First off I love this repo and this DIY workshop idea. Thank you for putting this together!

I would like to take this opportunity to make a small suggestion I think would improve the comprehension of newcomers like me. Yesterday during lessons 1-3 I was struggling to understand what was happening at first, then realized my data wasn't being reset. This issue came up because I ended up having to run the tests a few times while I experimented with the syntax. This left some tests adding data and others failing due to leftover state. I found the cy.request('POST', '/reset') call and then calling that in a beforeEach (just like lesson 4). Today I got to lesson 4 and I now see that you're assuming in lessons 1-3 people either won't need to run the test more than once because they input everything perfect.

I'd like to suggest moving lesson 4 up to the front and explaining that right away. Otherwise it leaves a bad taste when you have tests failing inexplicably. Thanks for your time Gleb. I really appreciate your efforts here. I hope this ticket helps improve this workshop.

PS: Great docs!

section on plugins

we have a lot of good plugins, would be nice to show off some of them

Test answers

Test most of the answers on CI by overwriting the ignoreTestFiles config from CLI or via an environment variable

Blocked by cypress-io/cypress#1696 that should be out in 3.3.2

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.