[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 ...
随机推荐
- vue打包问题:Tip: built files are meant to be served over an HTTP server.
npm run build之后,出现提示:Tip: built files are meant to be served over an HTTP server. Opening index.html ...
- 【NOIP2016】DAY1 T2 天天爱跑步
[NOIP2016]DAY1 T2 天天爱跑步 Description 小c同学认为跑步非常有趣,于是决定制作一款叫做<天天爱跑步>的游戏.?天天爱跑步?是一个养成类游戏,需要玩家每天按时 ...
- [ USACO 2018 OPEN ] Out of Sorts (Platinum)
\(\\\) \(Description\) 对一长为\(N\)的数列\(A\)排序,不保证数列元素互异: 数列\(A\)中\(A[1...i]\)的最大值不大于\(A[i+1-N]\)的最小值,我们 ...
- 来自一个用户的体验-Alpha项目测试
软件梦之队成员:201731062305 周蓉 这个作业属于哪个课程 <课程的链接> 这个作业要求在哪里 <作业要求的链接> 团队名称 <软件梦之队>(附上团队博客 ...
- webstorm进行VisualSVN配置及上传项目到项目库
以前建站一直都是自己一个人,最近要做一个比较大的网站,寻思着利用svn在整个开发过程中会比较快,于是摸索着配置了一下. 首先,下载VisualSVN这个软件,官网链接 https://www.visu ...
- Canvas清空
当canvs与bitmap绑定时,canvas上绘制会导致bitmap改变内容,而且内容时叠加的.这时候需要清空bitmap上的内容,可以用以下做法. Paint paint = new Paint( ...
- Android Studio查看CPU使用率。
进入AS自带的CMD,依次输入: (1)进入Android Atudio安卓的目录: 1.H: 2.cd AndroidStudio\sdk\platform-tools (2)adb shell ( ...
- javascript部分知识点
1:script放置位置: a:<title></title>之后 b:<body>之后 c:<body>中的<div></div&g ...
- 【转载】HTTP 响应头与状态码
原文地址:https://segmentfault.com/a/1190000006689786 HTTP Response Header 响应头域允许服务器传递不能放在状态行的附加信息,这些域主要描 ...
- dos命令在vba中应用
正常情况下想要遍历文件夹和子文件夹,可以采用递归的方式 Sub ListFilesTest() With Application.FileDialog(msoFileDialogFolderPicke ...