[Cypress] Create True end-to-end Tests with Cypress (Smoke test)
Integration tests let us keep our tests fast and reliable. They also allow us to test scenarios that are hard to recreate in a full end-to-end setup. That being said, we should round out our test suite with some high-level smoke tests. In this lesson, we’ll create some tests that seed our data-source and avoid stubbing our network calls, allowing us to test all parts of the application while using known data to keep our tests flake-free.
describe('Smoke Tests', () => {
// context is no difference with describe in functionality
context('No Todos', () => {
it('Adds a new todo', () => {
cy.server()
cy.route('POST', '/api/todos').as('save')
cy.visit('/')
cy
.get('.new-todo')
.type('New todo')
.type('{enter}')
cy.wait('@save')
cy.get('.todo-list li').should('have.length', )
})
})
});
Now we have post a new todo to the backend, it will pass the test.
But the problem is that, when you rerun the test again, it will faild, because now in the db, we have two todos.
Therefore, we need to clear the db everytime before we run the test:
describe('Smoke Tests', () => {
beforeEach(() => {
cy.request('DELETE', '/api/todos/all')
})
// context is no difference with describe in functionality
context('No Todos', () => {
it('Adds a new todo', () => {
cy.server()
cy.route('POST', '/api/todos').as('save')
cy.visit('/')
cy
.get('.new-todo')
.type('New todo')
.type('{enter}')
cy.wait('@save')
cy.get('.todo-list li').should('have.length', 1)
})
})
})
Another example:
context('With todos', () => {
beforeEach(() => {
cy.fixture('todos').then(todos => {
cy.request('POST', '/api/todos/bulkload', {todos})
})
cy.server()
cy.route('GET', '/api/todos').as('load')
cy.visit('/')
cy.wait('@load')
})
it('Deletes todos', () => {
cy.route('DELETE', '/api/todos/*').as('delete')
cy
.get('.todo-list li')
.each($el => {
cy
.wrap($el)
.find('.destroy')
.invoke('show')
.click()
cy.wait('@delete')
})
.should('not.exist')
})
})
About smoke test
[Cypress] Create True end-to-end Tests with Cypress (Smoke test)的更多相关文章
- Cypress系列(1)- Window下安装 Cypress 并打开
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 系统要求 Cypress 是一个被安装在 ...
- [Cypress] Create Aliases for DOM Elements in Cypress Tests
We’ll often need to access the same DOM elements multiple times in one test. Your first instinct mig ...
- [Cypress] Create a Single Custom Cypress Command from Multiple Commands
Cypress provides a straightforward API that allows you to define custom commands. In this lesson, we ...
- Cypress系列(44)- 命令行运行 Cypress
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 前面也介绍过 Cypress 命令 ...
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part1
Despite the fact that Cypress is an application that runs natively on your machine, you can install ...
- Cypress测试工具
参考博客: https://testerhome.com/articles/19035 最近一段时间学习了cypress的测试工具, 她是一个端到端的测试web工具. 环境准备 1.工具:vs co ...
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part3
Use custom Cypress command for reusable assertions We’re duplicating quite a few commands between th ...
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part2
Use Cypress to test user registration Let’s write a test to fill out our registration form. Because ...
- [Cypress] Get started with Cypress
Adding Cypress to a project is a simple npm install away. We won’t need any global dependencies beyo ...
随机推荐
- ACM_夏天到了,又到了出游的季节
夏天到了,又到了出游的季节 Time Limit: 2000/1000ms (Java/Others) Problem Description: QWER最近无心打代码,于是带着n套衣服出去浪.但是每 ...
- ACM_Mystery
Mystery Time Limit: 2000/1000ms (Java/Others) Problem Description: No Description Input: The first l ...
- 国内外知名IT科技博客
国内 1.36氪(www.36kr.com): 目前国内做的最风生水起的科技博客,以介绍国内外互联网创业新闻为主的博客网站,自己建立有36Tree互联网创业融投资社区.36氪的名字源于元素周期 表的第 ...
- Android通过透明度设置背景变暗
变暗 WindowManager.LayoutParams lp=getWindow().getAttributes(); lp.alpha=0.3f; getWindow().addFlags(Wi ...
- windows ping 某个网段,不能运行指定的软件
windows ping 某个网段,不能运行指定的软件 :begin @echo OFF color 0a Title Net Test Tool by:HRuinger Mode con cols= ...
- Java class对象说明 Java 静态变量声明和赋值说明
先看下JDK中的说明: java.lang.Object java.lang.Class<T> Instances of the class Class represent cla ...
- 使用码云gitee.com托管代码
1.新建项目 可以看到团队资源管理器是这样的,已经在本地有存储库,所有更改可以保存本地 2.在码云上新建项目 项目名称必填,其它项根据情况填写 3.复制项目地址关联到本地存储库 填写码云的项目地址,发 ...
- 微信 之jsapi实现支付
一.微信公众号号后台支付配置 附微信支付参考文档:https://pay.weixin.qq.com/wiki/doc/api/index.html 二.微信支付类封装 该类可以实现付款码支付.JSA ...
- 数组的复制 --System.arraycopy()
import java.util.Arrays; public class HellowWorld { public static void main(String[] argv ) { int[] ...
- 数组题汇总(python3)
题目主要来自<剑指offer>和LeetCode,用python3来写的代码. 1.二维数组的查找: 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列 ...