In this lesson well stub a POST request and use Cypress commands to fill in and submit a form. We’ll wait for the submission to resolve and then assert that the new item was added to the list.

For example when we dealing with Form submition, we want to issue a new POST request and then check it should update number of todos.

    it.only('should post new todo to the backend', function () {
// Serve the page
cy.server(); // Prepare a POST request
cy.route({
method: 'POST',
url: '/api/todos',
response: {id: 123, name: 'new todo', isComplete: false}
}).as('save'); // Call a custom command to load initial todos
cy.seedAndVisit(); // Enter a new todo
cy.get('.new-todo')
.type('new todo')
.type('{enter}'); // Wait network request to be finished
cy.wait('@save'); // Calculate the expected length of todos
cy.get('.todo-list li')
.should('have.length', 5);
}); // command
Cypress.Commands.add('seedAndVisit', (seedData = 'fixture:todos') => {
cy.server()
cy.route('GET', '/api/todos', seedData).as('load') cy.visit('/') cy.wait('@load')
});

最新文章

  1. TestNG中的数据源DataProvider概述
  2. Jmeter调试工具---Debug Sampler
  3. Weblogic 启动报错:java.lang.NoClassDefFoundError
  4. chat
  5. ubuntu下php开发环境搭建,nginx+(cgi)php5fpm+memcached+xdebug
  6. 使用Preference保存设置
  7. POJ 3045 Cow Acrobats (贪心)
  8. NetCore1.1+Linux部署初体验
  9. javascript 推箱子游戏介绍及问题
  10. Core文件简单介绍及生成设置方法
  11. Python——爬取人口迁徙数据(以腾讯迁徙为例)
  12. 《SSO CAS单点系列》之 APP原生应用如何访问CAS认证中心
  13. 九、.net core用orm继承DbContext(数据库上下文)方式操作数据库
  14. 如何查看.net framework 版本
  15. Java NIO中的通道Channel(二)分散/聚集 Scatter/Gather
  16. Git每次进入都需要输入用户名和密码的问题解决
  17. Mac 流程图
  18. Java设计模式(10)代理模式(Proxy模式)
  19. 【原创】Junit4详解二:Junit4 Runner以及test case执行顺序和源代码理解
  20. HTML/CSS权值继承

热门文章

  1. strupr函数
  2. Mac使用bootcamp安装win8.1出现网卡驱动没有安装问题
  3. [转]在 Linux 下使用 RAID
  4. java环境搭建(及安装问题“No repository found containing”解决) 并创立第一个java程序
  5. css每次的初始化代码
  6. Android 基础知识图谱
  7. 编写高质量的js之恰当选用if和switch
  8. Java程序员2016年终总结
  9. Android控件的继承关系
  10. lldb e、@weakify(self) 网络请求400错误