Gleb Bahmutov PRO
JavaScript ninja, image processing expert, software quality fanatic
VP of Engineering, Cypress.io
(part 2 at https://slides.com/bahmutov/selenium-camp-part-2)
C / C++ / C# / Java / CoffeeScript / JavaScript / Node / Angular / Vue / Cycle.js / functional / testing
🖥 🇬🇧
🗣 🇷🇺
❤️ 🇺🇦
18 people. Atlanta, Philly, Boston, Chicago, NYC
Fast, easy and reliable testing for anything that runs in a browser
Will Klein
Quality software behaves the way users expect it to behave
E2E
integration
unit
E2E
integration
unit
E2E
integration
unit
E2E
integration
unit
Really important to users
Really important to developers
E2E
integration
unit
Your tests
Selenium
Driver
FF, Chrome , IE
Your tests
Selenium
Driver
FF, Chrome , IE
✅ JavaScript, Java, Python, C#, etc
Your tests
Selenium
Driver
FF, Chrome , IE
⚠️ HTTP request
Your tests
FF, Chrome , IE
slow, flaky, unreliable tests
Your tests
Headless browser
What is happening?
People testing with Selenium / WebDriver
Cypress users?
No E2E tests
Electron based cross-platform app
Your tests
Your web app
Cypress App
start
Chrome (for now)
and many, many more resources,
only runs JavaScript
Install Node tools and 3rd party dependencies
# start new Node project
npm init
# add Cypress dependency
npm install --save-dev cypress
# open Cypress
npx cypress open
Cross-platform JavaScript environment
another useful tool included in Node
$ npm install -D cypress
npx cypress open
cypress.json - customize Cypress settings
npx @bahmutov/cly init
// ui-spec.js
it('loads the app', () => {
cy.visit('http://localhost:3030')
cy.get('.todoapp').should('be.visible')
})
Mocha BDD syntax
Chai assertions
it('adds 2 todos', () => {
cy.visit('http://localhost:3000')
cy.get('.new-todo')
.type('learn testing{enter}')
.type('be cool{enter}')
cy.get('.todo-list li')
.should('have.length', 2)
})
fluent API like jQuery
it('adds 2 todos', () => {
cy.visit('http://localhost:3000')
cy.get('.new-todo')
.type('learn testing{enter}')
.type('be cool{enter}')
cy.get('.todo-list li')
.should('have.length', 2)
})
assertions
commands
import {resetDatabase} from '../utils'
const visit = () => cy.visit('/')
describe('UI', () => {
beforeEach(resetDatabase)
beforeEach(visit)
context('basic features', () => {
it('starts with zero items', () => {
cy.get('.todo-list')
.find('li')
.should('have.length', 0)
})
})
})
bundling included
base url in cypress.json
cy.request, cy.task, cy.exec
1 * 👀 > 100 * 👂
types/
index.d.ts
package.json
"types": "types"
Explains global "
User test - just add this comment
Explains "cy.visit" command
Completion for BDD assertions
Completion for specific assertion with examples
every command and assertion
links to full docs
inline examples
80 commands + events + utilities (lodash, moment, jQuery) + assertions
Every command
Tutorials
Api
Examples
Video course
Full workshop
VSCode: in the user settings, global or workspace set:
{
"json.schemas": [
{
"fileMatch": ["cypress.json"],
"url": "https://on.cypress.io/cypress.schema.json"
}
]
}
VSCode alternative: add "$schema" property to your JSON file
{
"viewportWidth": 600,
"viewportHeight": 800,
"ignoreTestFiles": "answer.js",
"baseUrl": "http://localhost:3000",
"$schema": "https://on.cypress.io/cypress.schema.json"
}
it('adds items', function () {
cy.get('.new-todo')
.type('todo A{enter}')
.type('todo B{enter}')
.type('todo C{enter}')
.type('todo D{enter}')
cy.get('.todo-list li').should('have.length', 2)
})
command
assertion
it('adds items', function () {
cy.get('.new-todo')
.type('todo A{enter}')
.type('todo B{enter}')
.type('todo C{enter}')
.type('todo D{enter}')
cy.get('.todo-list li', {timeout: 1000000})
.should('have.length', 2)
})
helping live web application during the test
stay for Part 2
(part 2 at https://slides.com/bahmutov/selenium-camp-part-2)
By Gleb Bahmutov
Part 1. Modern web application testing is a hard and ungrateful job. But maybe this is just because we still don’t have a great tool for testing, that could be our friend not enemy? In this talk, I will present you Cypress.io – free test runner made without Selenium or WebDriver. With Cypress you could make your tests quick, simple and useful. Presented at SeleniumCamp in Ukraine, video at https://www.youtube.com/watch?v=hk4qtXgL12k
JavaScript ninja, image processing expert, software quality fanatic