[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 might be to use cy.getand assign the result to a variable for reuse. This might appear to work fine at first, but can lead to trouble. Everything in Cypress is done asynchronously and you’re interacting with an application’s DOM, which is changing as your tests interact with it. In this lesson, we’ll see how we can reference DOM elements in multiple places with the alias feature in Cypress.
it('should Delete an item', function () {
cy.server();
cy.route({
method: 'DELETE',
url: '/api/todos/*',
response: {}
}).as('delete');
cy.seedAndVisit();
cy.get('.todo-list li')
.first()
.find('.destroy')
.invoke('show') // Make the hidden button appear
.click();
cy.wait('@delete');
cy.get('.todo-list li')
.should('have.length', 3);
});
The code above, we have use 'cy.get('.todo-list li')' in two places.
We can use alias for DOM element as well to reduce duplication:
it('Using alias for the DOM element', function () {
cy.server();
cy.route({
method: 'DELETE',
url: '/api/todos/*',
response: {}
}).as('delete');
cy.seedAndVisit();
cy.get('.todo-list li')
.as('list'); // alias the DOM element
cy.get('@list')
.first()
.find('.destroy')
.invoke('show')
.click();
cy.wait('@delete');
cy.get('@list')
.should('have.length', 3);
});
[Cypress] Create Aliases for DOM Elements in Cypress Tests的更多相关文章
- [Cypress] Create a Single Custom Cypress Command from Multiple Commands
Cypress provides a straightforward API that allows you to define custom commands. In this lesson, we ...
- [D3] Create DOM Elements with D3 v4
Change is good, but creating from scratch is even better. This lesson shows you how to create DOM el ...
- Adding DOM elements to document
1.JavaScript 添加DOM Element 执行效率比较: 抄自:http://wildbit.com/blog/2006/11/21/javascript-optimization-add ...
- [D3] Select DOM Elements with D3 v4
Before you can create dazzling data driven documents, you need to know how D3 accesses the DOM. This ...
- [D3] Modify DOM Elements with D3 v4
Once you can get hold of DOM elements you’re ready to start changing them. Whether it’s changing col ...
- ReactDOM & DOM Elements
一.ReactDOM 1.1 render() ReactDOM.render(element,container,[callback]) 在container中渲染一个React元素,然后返回组件一 ...
- [Cypress] Create True end-to-end Tests with Cypress (Smoke test)
Integration tests let us keep our tests fast and reliable. They also allow us to test scenarios that ...
- [Javascript] Create scrollable DOM elements with Greensock
In this lesson, we will look at Greensock's Draggable API. We will implement a scrollable <div> ...
- [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 ...
随机推荐
- Django与 Ajax
什么是json? 定义: JSON(JavaScript Object Notation, JS 对象标记) 是一种轻量级的数据交换格式.它基于 ECMAScript (w3c制定的js规范)的一个子 ...
- ACM_情人节
情人节 Time Limit: 2000/1000ms (Java/Others) Problem Description: 某发每天都在各大群水啊水,然后认识了很多崇拜他的妹子,毕竟是数学专业.这不 ...
- day03_12/13/2016_bean属性的设置之构造器方式注入
- Rsync 传输不需要输入密码
1.背景 1) 一个作为服务器端:VM3(IP: 3.9.8.151) 2) 一个作为客户端:VM2(IP: 3.9.8.157) 3) 服务器端和客户端网络 ...
- Java class对象说明 Java 静态变量声明和赋值说明
先看下JDK中的说明: java.lang.Object java.lang.Class<T> Instances of the class Class represent cla ...
- java设计模式03装饰者者模式
动态地给一个对象添加一些额外的职责.就增加功能来说, Decorator模式相比生成子类更为灵活.该模式以对客 户端透明的方式扩展对象的功能. (1)在不影响其他对象的情况下,以动态.透明的方式给单个 ...
- SetACL 使用方法详细参数中文解析
示例: SetACL.exe c:\nihao /dir /deny everyone /read_ex 设置E:\wxDesktop 文件夹 everyone 用户为读取和运行权限 SetACL M ...
- Django - Ajax基本内容整理
将原来的请求结果普通字符串,变更为类字典的字符串 从这段代码中,可以看到,对原有函数,进行了一个try ...except....操作,进行异常捕捉,将捕捉过程及结果,存入在初始化的字典中,将字典通过 ...
- Django - 数据获取
Django - 数据获取 1.radio值获取 2.checkbox获取 3.select 获取 select 获取值,需要根据前端multiple来获取,get or getlist; 4.上传文 ...
- 小实例 hangman game
代码 #include <bits/stdc++.h> using namespace std; int bk[110]; string sj(int t) { string ans=&q ...