[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 ...
随机推荐
- BZOJ 3998 后缀数组
思路: 第一问 建出来后缀数组以后 前缀和一发n-sa[i]-ht[i]+1 二分 第二问 二分判断是带重复的第几 怎么判断呢 找到它 往后扫ht递减sum+=它 跟K判判 注意等于 加 ...
- js 中的定时器
在js中的定时器分两种:1.setTimeout() 2.setInterval() 1.setTimeOut() 只在指定时间后执行一次 /定时器 异步运行 function hello(){ al ...
- [转]linux之pr命令
转自:http://www.bitscn.com/plus/view.php?aid=6638 本文介绍如何使用Linux的pr命令将大文件分割成多个页面进行打印,并在每个页面上加上标题. Linux ...
- [转]android-学习笔记之按钮事件
本文转载自: http://zhangkun716717-126-com.iteye.com/blog/761080 前备知识: 1.需要了解怎么得到界面元素. 那么如何得到界面元素呢?在界面配置文件 ...
- 【转】Java 集合系列09之 Map架构
概要 前面,我们已经系统的对List进行了学习.接下来,我们先学习Map,然后再学习Set:因为Set的实现类都是基于Map来实现的(如,HashSet是通过HashMap实现的,TreeSet是通过 ...
- 客户端通过base64上传bitmap服务器
首先致谢:http://www.jb51.net/article/129743.htm 咱们不是代码的生产者,只是代码的搬运工. 场景描述:Android客户端需要上传头像等图片到服务器,经双方协商决 ...
- Java Web框架前景浅析
基于三(多)层架构模式,典型WEB系统的总体架构如下图所示: 在上述分层架构中,整个应用被划分为两大部分: 客户端:基于浏览器提供信息展现.用户交互等功能.所采用的技术主要有:HTML/HTML5.J ...
- servlet-响应的定时刷新
package servlet; import java.io.IOException; import javax.servlet.ServletException; import javax.ser ...
- C# 字符串的入门
1."@"表示字符串中的"\"不当成转义符. 2.转义符或者特殊处理的一些字符只是针对于代码中直接写出的字符串中,对于程序运行中读取出来的转义符或者特殊处理的字 ...
- 行动起来:转换传统桌面应用程序到UWP 并发布到Windows 应用商店!
一个月前微软发布了桌面应用程序转换器(Desktop Application Converter),让我们可以把现有的桌面应用程序(.NET 4.6.1 或 Win32)轻松转换成 通用 Window ...