[Cypress] Wait for XHR Responses in a Cypress Test
2024-08-31 05:52:37
When testing interactions that require asynchronous calls, we’ll need to wait on responses to make sure we’re asserting about the application state at the right time. With Cypress, we don’t have to use arbitrary time periods to wait. In this lesson, we’ll see how to use an alias for a network request and wait for it to complete without having to wait longer than required or guess at the duration.
Cypress gives us 4 seconds to load the data, but what if the loading time is larger than 4 secods? then test will faild.
To prevent this, we as let Cypress wait unitl one XHR request finish to run the test:
it('should have four initial todos and waiting loaded', function () {
cy.server();
cy.route('GET', '/api/todos', 'fixture:todos')
.as('loadingTodos');
cy.visit('/');
cy.wait('@loadingTodos'); cy.get('.todo-list > li')
.should('have.length', 4);
});
最新文章
- API的非向后兼容性无论如何通常代表着一种比较差的设计
- C++拷贝构造函数(深拷贝,浅拷贝)
- VC++中,如何定义callback函数和它的触发事件?
- 【HDOJ】3652 B-number
- .NET垃圾回收与内存泄漏
- -_-#【Canvas】回弹
- 【转】android电池(五):电池 充电IC(PM2301)驱动分析篇
- Android开发中怎样调用系统Email发送邮件(多种调用方式)
- NTP时间服务器
- Scrum 冲刺 第三日
- dedecms给图片加水印覆盖整张图片
- PowerDesigner概念(概念数据模型概述)
- SQL Server进阶 窗口函数
- React项目中实现右键自定义菜单
- 关于手贱--npm 误改全局安装路径
- 2019.02.15 codechef Favourite Numbers(二分+数位dp+ac自动机)
- 修复PLSQL Developer 与 Office 2010的集成导出Excel 功能
- 【ATcoder】Xor Sum 2
- Java获取系统日期时间
- [转]ZooKeeper学习第一期---Zookeeper简单介绍
热门文章
- linux下如何使用sftp命令进行文件上传和下载
- linux下安装rabbitmq以及在spring中进行集成
- (三)Appium-desktop 打包
- Elasticsearch之批量操作bulk
- CSS中的五大字体家族(cursive 手写字体族更吸引我)
- 【java基础】(1)Java的权限修饰符(public,protected,default,private)
- android指纹识别、拼图游戏、仿MIUI长截屏、bilibili最美创意等源码
- Monad (functional programming)
- 视频及MP3 播放浅析 Jplayer参数详细
- python中*的用法