In this lesson, we’ll add tests that finds a focused input. We’ll use Chrome’s dev tools from inside the Cypress runner to inspect the element and update our test to verify that the expected element is focused. We’ll see how Cypress can be used to test drive our application by creating a failing test and updating our application code to make it pass.

For exmaple in the todo app, when the page loaded, we want to test,

  • whether the input field is focused
  • whether the value of input filed is empty
  • whether the placeholder of the input field is "What needs to be done?"

The component code we have:

import React from 'react'export default props =><form onSubmit={props.handleTodoSubmit}><inputtype='text'autoFocusvalue={props.currentTodo}onChange={props.handleNewTodoChange}className="new-todo"placeholder="What needs to be done?"/></form>

The test code:

form-input.spec.js:

describe('Form input', function () {it('should has input filed auto focused when page loaded', function () {cy.visit('/');cy.focused().should('have.class', 'new-todo').and('have.attr', 'placeholder', 'What needs to be done?').and('be.empty');});
});

API, Github

转载于:https://www.cnblogs.com/Answer1215/p/9085115.html

[Cypress] Find and Test Focused Input with Chrome’s DevTools in Cypress相关推荐

  1. 关于 input在 chrome 、IE浏览器中遇到的兼容性问题处理

    1.谷歌中input自动填入后会出现背景色处理 input CSS样式 input:-webkit-autofill , textarea:-webkit-autofill, select:-webk ...

  2. Chrome 73 DevTools 新功能之 Logpoints

    前言 今天早上 Chrome 更新到 73 版本,其中 Logpoints 对于常用 console.log 的开发者来说,有较大的便捷性. 版本说明 本篇文章提到的 Chrome 73 的版本为: ...

  3. Chrome中devtools安装

    1.官网下载 下载压缩包即可 https://github.com/vuejs/devtools/releases 我先使用npm安装 但是下载依赖总报错 npm install -g cnpm -- ...

  4. python selenium chrome 控制devtools 一些线索

    chrome webdriver下载地址:http://chromedriver.storage.googleapis.com/index.html 注意和国产浏览器的内核版本对应(星愿浏览器80.0 ...

  5. chrome浏览器devtools切换主题(亮色,暗色)

    打开devtools,windows下使用快捷键ctrl+shift+p打开command命令,mac用户使用command+shift+p.输入theme则可看见切换命令选中即可. 切换到亮色 切换 ...

  6. 通过一个简单的例子,了解 Cypress 的运行原理

    Cypress 是 SAP Spartacus 前端 e2e 测试使用的框架. Cypress 并不是广义上的 web 自动化工具,并不适合编写脚本来测试已经处于生产状态下的不受测试者控制的网站. C ...

  7. cypress 自动化测试

    文章目录 前言 一.简介 二.原理 三.特性 四.优势 五.安装使用 1. npm install cypress --save-dev # 安装cypress 1.1 在项目根目录下增加配置文件cy ...

  8. E2E 端到端测试学习 - E2E 介绍、Cypress 案例基本使用

    E2E 测试介绍 E2E E2E(end to end)端到端测试是最直观可以理解的测试类型.在前端应用程序中,端到端测试可以从用户的视角通过真实浏览器自动检查应用程序是否正常工作. E2E 把整个系 ...

  9. 屏幕分辨率测试工具(舍弃)---chrome开发者工具devTools(强烈建议系统学习)

    2019-01-25 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://w ...

最新文章

  1. python下载方法-python实现下载文件的三种方法_python
  2. 数据结构源码笔记(C语言):线性表的顺序表示
  3. boxfilter 函数
  4. 获取Class对象的三种方式
  5. 聊聊高并发(二十七)解析java.util.concurrent各个组件(九) 理解ReentrantLock可重入锁
  6. 操作系统和数据库的知识梳理(思维导图)
  7. linux访问nfs端口号,linux nfs配置及访问控制
  8. ztree 实例地址
  9. 新年第一天,3000台Apache服务器宕机
  10. 幸运抽奖游戏系统带后台源码
  11. U盘PE安装原版Win10系统
  12. 为什么onenote一直在加载_【完美解决】11.OneNote中英文字体不统一,微软10多年未解决的Bug!...
  13. 【c语言】两个栈实现一个队列
  14. 重要文件即时搞定,不用插电就能打印,汉印MT800移动便携打印机上手
  15. linux机顶盒界面,基于嵌入式Linux的IPTV机顶盒的设计与实现
  16. 《进销存 ——“商品查询/新增”》
  17. 麻省理工学院计算机研究生读几年,2020年麻省理工学院一年制硕士含金量
  18. c++ const 全面总结!
  19. 彻底搞懂javascript中的replace函数
  20. 升级JFlash后无法连接JLINK问题处理

热门文章

  1. 从0到1告诉你搭建完整Python+requests接口自动化测试框架!
  2. 2021年吉林高考成绩怎么查询,2021年吉林高考成绩查询登录网址入口怎么查 附查询方法...
  3. java版selenium_Selenium3.0-Java版(共61节)
  4. html svg画图
  5. uiswitchbutton 点击不改变状态_ES6专题—Generator与react状态机(14)
  6. 嵌入式Linux入门9:Linux系统使用
  7. 【kafka】kafka 生态系统 Ecosystem
  8. 05-netty小例子
  9. 【Flink】Generic types have been disabled in the ExecutionConfig and type KryoSerializer Row
  10. 【ElasticSearch 】ElasticSearch监控工具 cerebro