[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 multiple tests with nearly identical code, we can take advantage of the JavaScript runtime and use normal data structures and plain old JavaScript to test and make assertions for multiple interactions in a single test.
we have a new fixture:
// cypress/fixtures/mixed_todos.json [
{ "id": 1, "name": "One", "isComplete": false },
{ "id": 2, "name": "Two", "isComplete": true },
{ "id": 3, "name": "Three", "isComplete": true },
{ "id": 4, "name": "Four", "isComplete": false }
]
In the app, when we click different visibility filter, the list will change accordingly.
To test this behavior in clean code, we can use '.wrap().each()' to test it
it('should Footer todos', function () {
cy.seedAndVisit('fixture:mixed_todos'); const filters = [
{ link: 'Active', expectedLength: 2 },
{ link: 'Completed', expectedLength: 2 },
{ link: 'All', expectedLength: 4 }
]; cy.wrap(filters)
.each(filter => {
// contains(): find the element contains the text
cy.contains(filter.link).click();
cy.get('.todo-list li').should('have.length', filter.expectedLength);
})
});
[Cypress] Test Variations of a Feature in Cypress with a data-driven Test的更多相关文章
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- [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 ...
- Cypress系列(0)- 如何学习 Cypress
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 Cypress 未来很有可能会火的 ...
- Cypress系列(13)- 详细介绍 Cypress Test Runner
如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 Test Runner 也叫运行器 ...
- 【cypress】2. 安装Cypress(windows系统),以及cypress open报错解决。
安装cypress. 一.操作系统 先确认下你的系统,是否在cypress支持范围之内: macOS 10.9 以上 (仅64-bit) Linux Ubuntu 12.04及以上版本,Fedora ...
- [Cypress] install, configure, and script Cypress for JavaScript web applications -- part4
Load Data from Test Fixtures in Cypress When creating integration tests with Cypress, we’ll often wa ...
随机推荐
- 第一个只出现一次的字符--java实现
/** * 主要思想是通过数组来保存每个字符的出现次数,数组访问O(1),所以总时间复杂度可以保持O(n),通过两次遍历可以解决问题 * @param ch * @return */ public s ...
- BZOJ 2592 随机化(伪)
思路: 放yousiki大爷题解 http://yousiki.net/index.php/archives/82/ 我写的是随机化 既然gzz证了最终答案的上界是O(N)的 那么我们可以n^2枚举所 ...
- python网络爬虫之图片链家在技术.seleninum和PhantonJS
一.什么是图片懒加载? 案例分析:抓取站长素材http://sc.chinaz.com/中的图片数据 #!/usr/bin/env python # -*- coding:utf-8 -*- impo ...
- django 菜单权限
一.什么是权限 能做哪些事情,不能做哪些事情,可以做的权限 二.设计权限 思路: web应用中,所谓的权限,其实就是一个用户能够访问的url,通过对用户访问的url进行控制,从而实现对用户权限的控制. ...
- Mac OS安装octave出现的问题-'error:terminal type set to 'unknown'的解决'
学习Machine learning需要使用Octave语言,毕竟Andrew Ng (恩达.吴)力荐.本机系统Mac OS X EI Capitan, 其实什么系统都无所谓了,安装原理都是一样的. ...
- Linux egrep命令
Linux egrep命令用于在文件内查找指定的字符串. egrep执行效果与"grep-E"相似,使用的语法及参数可参照grep指令,与grep的不同点在于解读字符串的方法. e ...
- 在Swift中,如何像Objective-C定义可选接口?
Objective-C中的protocol里存在@optional关键字,被这个关键字修饰的方法并非必须要被实现.我们可以通过接口定义一系列方法,然后由实现接口的类选择性地实现其中几个方法.在Coco ...
- java DDD 基于maven开发的探讨
对于DDD我目前的理解是 1.除了数据的基本操作,也可以把一些公用的方法或者类迁移到Infrastructrue 2.对于domain层可以声明各个聚合根的操作接口:例:IXXXRepository ...
- [ SHOI 2001 ] 化工厂装箱员
\(\\\) \(Description\) 传送带上按顺序传过来\(N\)个物品,一个有\(A,B,C\)三类. 每次装箱员手里只能至多拿十个,然后将手中三类物品中的一类装箱,才能接着拿或接着装箱, ...
- [原创]Toolbar setNavigationIcon无效
最近在做一个Toolbar,setNavigationIcon()这个方法一直无效,说什么的都有,什么getSupportActionBar().setNavigationIcon()的,说设置sty ...