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)的更多相关文章

  1. Cypress系列(1)- Window下安装 Cypress 并打开

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 系统要求 Cypress 是一个被安装在 ...

  2. [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 ...

  3. [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 ...

  4. Cypress系列(44)- 命令行运行 Cypress

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 前面也介绍过 Cypress 命令 ...

  5. [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 ...

  6. Cypress测试工具

    参考博客:  https://testerhome.com/articles/19035 最近一段时间学习了cypress的测试工具, 她是一个端到端的测试web工具. 环境准备 1.工具:vs co ...

  7. [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 ...

  8. [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 ...

  9. [Cypress] Get started with Cypress

    Adding Cypress to a project is a simple npm install away. We won’t need any global dependencies beyo ...

随机推荐

  1. 关于网页的自适应问题一---Media Query(媒介查询)

    1.Media Query(媒介查询) 通过不同的媒介类型和条件定义样式表规则.媒介查询让CSS可以更精确作用于不同的媒介类型和同一媒介的不同条件.媒介查询的大部分媒介特性都接受min和max用于表达 ...

  2. C#中 分层 显示数据库中多表的数据信息

    如下图,要实现将三个表中的内容加载到同一个窗体中,该怎么来实现呢? 要实现上面的查询结果,我们就要从Student表中拿到学生姓名,从Subject表中拿到科目名称,从StudentResult表中拿 ...

  3. Android 将图片网址url转化为bitmap

    public Bitmap returnBitMap(final String url){ new Thread(new Runnable() { @Override public void run( ...

  4. Android O Bitmap 内存分配

      我们知道,一般认为在Android进程的内存模型中,heap分为两部分,一部分是native heap,一部分是Dalvik heap(实际上也是native heap的一部分).   Andro ...

  5. Ajax——瀑布流

    基本概念 1.宽度是一致的,高度上参差不齐 2.新增内容优先放置在最矮的地方 核心难点 1.用一个数组存储每列的高度值 2.新值添加到值最小索引上,每次替换更新数组 插件使用 1.$.fn.exten ...

  6. html——ico

    下载: 网址+/favicon.ico 引用: 1.<link href="favicon.ico" rel="icon" /> 2.<lin ...

  7. JS——动态添加事件和移除事件(有待补充...)

    动态的添加事件:利用 attachEvent 和 addEventListener IE 支持 attachEvent: obj.attachEvent("onclick", Fo ...

  8. O-理解共享池

    我们可以通过show sga命令查看共享池的整体组成部分: ....待截图.... 一.SGA内存结构 Oracle中SGA主要包括: 1.固定数据结构部分(FIXED Size) 2.数据块缓冲区( ...

  9. Python元类(metaclass)以及元类实现单例模式

    这里将一篇写的非常好的文章基本照搬过来吧,这是一篇在Stack overflow上很热的帖子,我看http://blog.jobbole.com/21351/这篇博客对其进行了翻译. 一.理解类也是对 ...

  10. docker安装后出现Cannot connect to the Docker daemon

    启动docker service docker start docker安装后出现Cannot connect to the Docker daemon You need to add user in ...