[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‘, 1)

        })
    })

});

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

原文地址:https://www.cnblogs.com/Answer1215/p/9270948.html

时间: 2024-10-06 02:13:44

[Cypress] Create True end-to-end Tests with Cypress (Smoke test)的相关文章

Cypress 系列之----03自定义命令Custom Commands

// *********************************************** //本篇主要针对创建各种自定义命令,重写命令,官方参考资料:https://on.cypress.io/custom-commands // // *********************************************** // -- This is a parent command --父命令,用cy可以直接调用 // Cypress.Commands.add('login

[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 the registration and login of our user for assertions. Let’s see how we can take these assertions and create a custom command to make the assertions. We

Cypress 之 环境配置

将项目添加到cypress时,cypress.json会在项目中创建一个文件,此文件用于存储projectId,以及你提供的任何配置项. 可以通过以下提供的任何配置选项来修改赛普拉斯的默认行为. 全局配置项 选项 默认 描述 baseUrl null 用作命令cy.visit()或cy.request()的前缀URL. env {} 设置任意环境变量. ignoreTestFiles *.hot-update.js 用于忽略测试文件的字符串或数组的glob模式,否则这些测试文件将显示在测试列表中

hibernate4.2.2使用schemaExport生成数据表报错,junit提示:SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: NO))

给mysql的root授权远程连接 1 mysql -u root –p 2 mysql>use mysql; 3 mysql>update user set host = '%' where user = 'root'; 4 mysql>select host, user from user; hibernate.cfg.xml的内容 1 <property name="connection.username">root</property>

[Cypress] Get started with Cypress

Adding Cypress to a project is a simple npm install away. We won’t need any global dependencies beyond node and npm to get started with Cypress. In this lesson we’ll look at our existing application, add Cypress as a dev dependency with npm and fire

Spark2.2+ES6.4.2(三十二):ES API之ndex的create(创建index时设置setting,并创建index后根据avro模板动态设置index的mapping)/update/delete/open/close

要想通过ES API对es的操作,必须获取到TransportClient对象,让后根据TransportClient获取到IndicesAdminClient对象后,方可以根据IndicesAdminClient对象提供的方法对ES的index进行操作:create index,update index(update index settings,update index mapping),delete index,open index,close index. 准备工作(创建Transpor

frist Django app — 五、Test

Test——很重要但是没有被重视起来的一个环节,至少是我自己,其实自己之前在做java web的时候就去尝试过怎么做REST接口的测试,一直没有找到一种合适方式,而且因为时间紧没有进一步深究,但是造成的后果每次做了修改之后都测试不充分,引起新的问题,所以这次对于python正好看看Django的单元测试. 用的是单独的数据库,数据库是干净的(暂未有数据库,test所有操作都是从零开始),不会对正式的数据库造成影响 Test Model 到现在我们主要的业务逻辑代码在model和view里面,所以

requerjs 合并 优化配置

/* * This is an example build file that demonstrates how to use the build system for * require.js. * * THIS BUILD FILE WILL NOT WORK. It is referencing paths that probably * do not exist on your machine. Just use it as a guide. * * */   ({     //The

EJBCA 在windows上的安装

为了做EJBCA的封装测试,在我自己电脑上装了个,但是在国内的开发上面的介绍实在是太少,有的也只是些傻瓜式的安装介绍,这是介绍在Windows上安装的过程,(后面介绍下 linux 红帽上的),有些也是在网上看看,有一些比较关键的地方 在下面会指出来: 推荐一个比较不错的网址:https://sourceforge.net/p/ejbca/discussion/ EJBCA Installation EJBCA是一个基于J2EE技术的全功能的开源CA系统软件,并提供了一个强大的.高性能并基于组件