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);
});

[Cypress] Wait for XHR Responses in a Cypress Test的更多相关文章

  1. [Cypress] Test XHR Failure Conditions with Cypress

    Testing your application’s behavior when an XHR call results in an error can be difficult. The use o ...

  2. [Cypress] Test Variations of a Feature in Cypress with a data-driven Test

    Many applications have features that can be used with slight variations. Instead of maintaining mult ...

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

  4. [Cypress] Interact with Hidden Elements in a Cypress Test

    We often only show UI elements as a result of some user interaction. Cypress detects visibility and ...

  5. [Cypress] Load Data from Test Fixtures in Cypress

    When creating integration tests with Cypress, we’ll often want to stub network requests that respond ...

  6. [Cypress] Test React’s Controlled Input with Cypress Selector Playground

    React based applications often use controlled inputs, meaning the input event leads to the applicati ...

  7. [Cypress] Use the Most Robust Selector for Cypress Tests

    Which selectors your choose for your tests matter, a lot. In this lesson, we'll see the recommended ...

  8. Cypress系列(0)- 如何学习 Cypress

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 Cypress 未来很有可能会火的 ...

  9. Cypress系列(13)- 详细介绍 Cypress Test Runner

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 Test Runner 也叫运行器 ...

随机推荐

  1. aspectc中this可以获取的东西

    this->kind  操作类型 this->targetName 被调用函数名称 this->funcName 调用函数名称 this->argsCount 参数个数 thi ...

  2. kafka参数在线修改

    当kafka集群单个节点出现磁盘满了,需要清理历史topic数据:方法如下 1): 停掉kafka进程,将kafka的server.properties中的log.retention.hours=1/ ...

  3. AOP实现参数的判空问题

    不想每次都去判断必传的参数是否为空,写代码太繁琐了,正好最近用了AOP实现权限控制,依葫芦画瓢,现在用它实现参数的判空,至于AOP的原理之类,自己百度了解一下吧 1. NullDisable注解 @D ...

  4. 关于VirtualBox与锐捷冲突导致锐捷不断掉线的问题的解决办法

    和VM一样,virtualBox也是和锐捷冲突,网上有一些方法是禁用虚拟网卡,但是还是会导致锐捷客户端掉线,除非使用wifi 第一个解决办法: 偶然看到一个解决办法是,在锐捷客户端登陆之后,打开任务管 ...

  5. oracle从入门到精通复习笔记

    为方便大家跟着我的笔记练习,为此提供数据库表文件给大家下载:点我下载 描述一个表用 desc employees过滤重复的部门 select distinct department_id from e ...

  6. 点云处理软件Pointscene

    转载于PCL中国:点云处理软件Pointscene 软件官网:https://pointscene.com/ 笔者评:        Pointscene是目前的点云处理软件之一,其主要是操作简单直观 ...

  7. MVC 数据传递

    public class HomeController : Controller { // GET: Home public ActionResult Index() //控制器名Home下默认的一个 ...

  8. Redis 之set集合结构及命令详解

    注:集合的元素具有唯一性,无序性 1.sadd  key   value1  value2  添加一个集合 2.smembers   key  获取一个集合的所有值 3.srem  key  valu ...

  9. PAT_A1126#Eulerian Path

    Source: PAT A1126 Eulerian Path (25 分) Description: In graph theory, an Eulerian path is a path in a ...

  10. python基础1 格式化输出

    转载自:https://www.cnblogs.com/fat39/p/7159881.html %用法 1.整数输出 %o —— oct 八进制%d —— dec 十进制%x —— hex 十六进制 ...