cypress-witch
v1.2.10
Published
A different way to write tests with Cypress
Downloads
22
Maintainers
Readme
cypress-witch is a test case automation library for Cypress. It makes your Cypress tests concise, structured and readable.
Features
- test structure becomes identical to test case specification
- test structure becomes readable and understandable by anyone
- enhanced logging makes failing tests review blazing fast
- can be easily integrated into existing workflow or code base
- easily extendable
Installation
npm i cypress-witch
In your cypress/plugins/index.js :
import { plugins } from 'cypress-witch/lib/plugins';
module.exports = (on, config) => {
on('task', {
...plugins,
})
}
Usage
With cypress-witch test is defined with testCase and consists of precondition(s), step(s) and expectedResult(s).
testCase accepts 3 arguments:
- title: string - test case title
- body: () => void - test case body
- hooks: () => void - optional - cypress hooks (before, beforeEach, after, afterEach)
Showcase wih example.cypress.io/todo
todo.spec.js
import { testCase, precondition, step, expectedResult } from 'cypress-witch';
testCase('User adds and edits new todo', {
body: () => {
const testData = {
newTodo: 'Feed the cat',
editedTodo: 'Feed the dog',
};
precondition('1: User is at cypress todo example', () => {
cy.visit('https://example.cypress.io/todo');
});
step('1: User adds new todo', () => {
cy.get('[data-test=new-todo]')
.type(`${testData.newTodo}{enter}`);
});
expectedResult('New todo is added', () => {
cy.get('.todo-list li')
.last()
.should('have.text', testData.newTodo);
});
step('2: User edits created todo', () => {
cy.get('.todo-list li')
.last()
.dblclick()
.clear()
.type(`${testData.editedTodo}{enter}`);
});
expectedResult('Todo item is edited', () => {
cy.get('.todo-list li')
.last()
.should('have.text', testData.editedTodo);
});
},
});
cypress run
cypress open