Which selectors your choose for your tests matter, a lot. In this lesson, we'll see the recommended Cypress best practices for selectors, and why we should prefer the data-cy attribute.

If you know that for React, the best pratice for testing is also adding:

data-test-id={`todo-item-${todo.id}`}

For Cypress:

<li
data-cy={"todo-item-" + todo.id}
className={classnames({
completed: todo.completed,
diting: this.state.editing
})}
></li>

spec:

cy.get("[data-cy=todo-item-3]")
.should("have.text", "Hello world")
.should("not.have.class", "completed")
.find(".toggle")
.should("not.be.checked");

[Cypress] Use the Most Robust Selector for Cypress Tests的更多相关文章

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

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

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

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

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

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

  6. [Cypress] Wait for XHR Responses in a Cypress Test

    When testing interactions that require asynchronous calls, we’ll need to wait on responses to make s ...

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

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

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

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

  9. 【cypress】2. 安装Cypress(windows系统),以及cypress open报错解决。

    安装cypress. 一.操作系统 先确认下你的系统,是否在cypress支持范围之内: macOS 10.9 以上 (仅64-bit) Linux Ubuntu 12.04及以上版本,Fedora ...

随机推荐

  1. Python if __name__ == '__main__': 理解

    if __name__ == '__main__':是为了区分.py文件是自己直接被执行还是被其他文件调用. 当.py文件直接被执行时,默认的是 __name__ = '__main__',因此条件成 ...

  2. java微信token校验

    1.微信验证接口 package com.park.utils.wechatUtil; import org.springframework.web.bind.annotation.RequestMa ...

  3. Linux系列(13)之程序与服务的概念

    知道如何区分程序与进程吗? 知道如何产生进程吗? 知道进程之间的相关性吗? 知道进程调用的流程吗? 知道进程与服务的区别吗? 1.程序与进程的区别 bash就是一个程序,当我们登录之后系统就会给我们分 ...

  4. Java:关于子类继承父类接口时,由于权限没有设定的更广,出错的一个小tip

    今天在写笔记的时候,写的地方出现了小叉叉错号. 发现问题: 这里出错了!原因是因为在子类覆写父类的方法的时候,权限不能开的比父类更低! 加了public后,纠错成功. 由于接口类型下的方法默认都是pu ...

  5. 网络编程之异步IO

    Linux的I/O模型有下面几种:1. 同步阻塞I/O: 用户进程进行I/O操作,一直阻塞到I/O操作完成为止.2. 同步非阻塞I/O: 用户程序可以通过设置文件描述符的属性O_NONBLOCK,I/ ...

  6. 【kmp】似乎在梦中见过的样子

    参考博客: BZOJ 3620: 似乎在梦中见过的样子 [KMP]似乎在梦中见过的样子 题目描述 「Madoka,不要相信QB!」伴随着Homura的失望地喊叫,Madoka与QB签订了契约. 这是M ...

  7. 我的第一个python web开发框架(2)——第一个Hello World

    小白中午听完老菜讲的那些话后一直在思考,可想来想去还是一头雾水,晕晕呼呼的一知半解,到最后还是想不明白,心想:老大讲的太高深了,只能听懂一半半,看来只能先记下来,将明白的先做,不明白的等以后遇到再学. ...

  8. MongoDB的复合唯一索引

    一 创建 JavaScript Shell db.room.ensureIndex({'floor':1,'num':1}) Spring Data @Data // lombok @Document ...

  9. [NOIP10.4模拟赛]2.y题解--折半搜索+状压计数

    题目链接: 咕 闲扯: 这题暴力分似乎挺多,但是一些奇奇怪怪的细节没注意RE了,还是太菜了 分析: 首先我们考虑最naiive的状压DP ,\(f[u][v][state]\)表示u开头,v结尾是否存 ...

  10. 判断两个list是否元素一样

    首先创建枚举 public enum TheType { type1 = , type2 = , type3 = } 1.如果不考虑顺序,即顺序不一样,只要元素都一样即可 List<TheTyp ...