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}>
<input
type='text'
autoFocus
value={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

[Cypress] Find and Test Focused Input with Chrome’s DevTools in Cypress的更多相关文章

  1. chrome通过devtools来查看Devtools Extension与浏览器内核实际通信的数据情况

    1.chrome通过devtools来查看Devtools Extension与浏览器内核实际通信的数据情况,步骤如下: (1)开启开发者工具实验模式 ---浏览器进入chrome://flags - ...

  2. [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 ...

  3. chrome调试工具DevTools的使用 以及 localhost在移动端不能访问的问题

    1.手机和pc 都需要装 chrome浏览器 2.手机端打开开发者模式和usb调试 (华为nova的手机小坑,需要选择usb 配置为可传输文件的状态) 3.经过以上操作打开chrome://inspe ...

  4. [转]chrome 的devtools 中setting 开启workspace , 也有点用处。不是很大

    转载的,原文: http://wiki.jikexueyuan.com/project/chrome-devtools/saving-changes-with-workspaces.html ---- ...

  5. Chrome Vue Devtools插件安装和使用

    安装:fq后在chrome应用商店搜索 Vue Devtools并安装,安装成功后浏览器右上角有vue的图标 安装完毕后,打开含有vue框架的网站,这是vue图标会变亮,进入开发者工具,再右侧vue选 ...

  6. 在Chrome与火狐中,输入框input类型为number时,如何去除掉的自带的上下默认箭头

    如何移除input='number'时浏览器自带的上下箭头: CSS样式: /* 去除input[type=number]浏览器默认的icon显示 */ input::-webkit-outer-sp ...

  7. puppeteer(五)chrome启动参数列表API

    List of Chromium Command Line Switches https://peter.sh/experiments/chromium-command-line-switches/ ...

  8. [Cypress] install, configure, and script Cypress for JavaScript web applications -- part2

    Use Cypress to test user registration Let’s write a test to fill out our registration form. Because ...

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

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

随机推荐

  1. hdu3652B-number(数位dp)

    B-number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  2. codevs2596 售货员的难题(状压dp)

    2596 售货员的难题  时间限制: 1 s  空间限制: 32000 KB  题目等级 : 钻石 Diamond     题目描述 Description 某乡有n个村庄(1<n<=15 ...

  3. JVM内存模型和GC垃圾回收

    JVM 内存区域 1.程序计数器 这是一块较小的内存空间,它的作用可以看做是当前线程所执行的字节码的行号指示器,指的是上次代码被执行的地方,线程私有. 2.Java 虚拟机栈 它是 Java方法执行的 ...

  4. RecastNavigation(3D场景建模、网格导航)

    一.RecastNavigation详解 RecastNavigation定义: RecastNavigation是一个导航寻路工具集,使用邻接的凸多边形集合描述一个3D场景,A*寻路算法使3D场景的 ...

  5. SnackDown Online Pre-elimination round A

    1. 应该n是偶数,就行吧.应该判断1个人,只能出现一次吧. #include<bits/stdc++.h> #define pb push_back typedef long long ...

  6. T - Amusing Joke(map)

    Problem description So, the New Year holidays are over. Santa Claus and his colleagues can take a re ...

  7. MySQL实现递归查询

    DROP FUNCTION IF EXISTS queryChildrenCaseInfo;CREATE FUNCTION queryChildrenCaseInfo(cId INT)RETURNS ...

  8. C#之调用存储过程

    C#调用存储过程   以下内容可能有错漏之处,请大家多多指教. C#后台代码如下: //调用存储过程的方法public static void Startupworkflow(string first ...

  9. Flex使用总结

    最近做的项目因为对浏览器的兼容要求是IE10以上,所以大胆的使用了Flex布局,这里总结一些使用心得仅供参考. 一,Flex简单介绍 Flex是Flexible Box的缩写,意为”弹性布局”.任何一 ...

  10. HTML+CSS(10)

    n  组合选择器 多元素选择器 n  描述:给多个元素加同一个样式,多个选择器之间用逗号隔开. n  举例:h1,p,div,body{color:red;} 后代元素选择器(最常用) n  描述:给 ...