[Cypress] Wait for XHR Responses in a Cypress Test
for in test WAIT Cypress
2023-09-14 08:59:17 时间
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); });
相关文章
- 解决MyBatis的报错 There is no getter for property named ‘*‘ in ‘class java.lang.String‘
- [文献阅读]Deep Metric and Hash-Code Learning for Content-Based Retrieval of Remote Sensing Images
- 【说站】python for…in循环的使用
- 【说站】JavaScript for-in和for-of的不同点
- ACDSee Photo Studio 9 for Mac(数字图像处理软件) v9.1.2689激活版
- Error:Execution failed for task ':app:packageDebug'. > Duplicate files copied in APK META-INF/LICENS
- Path Finder for Mac(强大的文件管理工具)v2149中文激活版
- ORA-00437: ORACLE feature is not licensed. Contact Oracle Corp. for assistance ORACLE 报错 故障修复 远程处理
- ORA-01300: writable database required for specified LogMiner options ORACLE 报错 故障修复 远程处理
- ORA-01719: outer join operator (+) not allowed in operand of OR or IN ORACLE 报错 故障修复 远程处理
- ORA-24039: Queue string not created in queue table for multiple consumers ORACLE 报错 故障修复 远程处理
- ORA-39092: unable to set SCN metadata for object “string.string” of type string ORACLE 报错 故障修复 远程处理
- ORA-41643: invalid attribute for the “string” element in the rule condition ORACLE 报错 故障修复 远程处理
- ORA-42288: may not create a schema synonym for the specified schema ORACLE 报错 故障修复 远程处理
- ORA-15702: duplicate values for plan line ID in input collection ORACLE 报错 故障修复 远程处理
- JS遍历数组(for in和forEach循环)
- MySQL中实现嵌套查询的IN关键字用法(mysql嵌套查询in)
- 目录用For循环创建Linux目录的简单技巧(for循环创建linux)
- 进程的方法Killing processes in Linux: useful commands for terminating current tasks(linux结束当前)
- Effective oracle techniques for conditionbased deduplication(oracle条件去重)
- Exploring the Benefits of SOC Linux for Embedded Systems in 2021(soclinux)
- MySQL中使用IN操作符的查询效率分析(mysql中in的效率)
- 提升Oracle IN操作中的性能改进(oracle in的性能)