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. centos6.5安装python3及virtualenv环境

    1. 下载源码: wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz wget http://mirrors.sohu.com/ ...

  2. jdk1.8 -- Collectors 的使用

    package com.collector; import java.util.ArrayList; import java.util.Arrays; import java.util.Collect ...

  3. jdk1.8 -- optional 的使用

    一.optional的介绍 Optional 是个容器:它可以保存类型T的值,或者仅仅保存null.Optional提供很多有用的方法,这样我们就不用显式进行空值检测. Optional 类的引入很好 ...

  4. yum源 epel源 替换及安装

    #!/bin/sh # 备份yum源 zip -r /etc/yum.repos.d/yum_resource_back_up.zip /etc/yum.repos.d/* # 替换yum源 wget ...

  5. 补码一位乘法 Booth算法 Java简易实现

    本文链接:https://www.cnblogs.com/xiaohu12138/p/11955619.html. 转载,请说明出处. 本程序为简易实现补码一位乘法,若代码中存在错误,可指出,本人会不 ...

  6. 关于日志slf4j+logback&logback.xml配置

    1.maven依赖 <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api --> <!-- <dependen ...

  7. k-近邻(KNN) 算法预测签到位置

    分类算法-k近邻算法(KNN): 定义: 如果一个样本在特征空间中的k个最相似 (即特征空间中最邻近) 的样本中的大多数属于某一个类别,则该样本也属于这个类别 来源: KNN算法最早是由Cover和H ...

  8. String的equals和hashCode方法

    对于判断对象是否相等,肯定需要重写它的equals和hashCode方法.不然使用默认的方法只会比较地址,因此会出现错误. 以String类为例,且看它的equals方法 public boolean ...

  9. Unity上线google商店 用IL2Cpp打包64位版本和Android APP Bundle优化 及产生的bug

    ios刚上线,这边着手改成android版本,我开始使用的是unity2017.4.1版本 上传谷歌商店是出现这两个警告: 要支持64位,但是在2017版本上没有找到64位的打包选项,猜测应该是版本的 ...

  10. datagrid如何获取选中行的索引

    //datagrid获取选中行 var row =baseSelectgrid.datagrid('getSelected'); // 获取被选中行的索引 index var index=baseSe ...