invoke()到底是个什么方法???

2024-03-11 18:12
文章标签 方法 到底 invoke

本文主要是介绍invoke()到底是个什么方法???,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

调用jquery的方法返回属性值
1、invoke(‘val’)
在form的select下:
在这里插入图片描述

 cy.get('.action-select-multiple').select(['apples', 'oranges', 'bananas'])// when getting multiple values, invoke "val" method first  jquery中val方法是用于返回或设置被选元素的value属性.invoke('val').should('deep.equal', ['fr-apples', 'fr-oranges', 'fr-bananas'])

所以从例子来看,就是用来调用jquery中的某个方法,如上调用val方法返回被选元素的value值。
通过断言多选的选项< option >的value属性值,来确保选项是选中的。

在这里插入图片描述

 it('.trigger() - trigger an event on a DOM element', () => {// https://on.cypress.io/trigger// To interact with a range input (slider)  通过一个范围的输入交互(滑块)// we need to set its value & trigger the 我们需要设置值&触发事件去通知他交互// event to signal it changed// Here, we invoke jQuery's val() method to set  通过invoke调用val方法获取value的值,触发change事件,// the value and trigger the 'change' eventcy.get('.trigger-input-range').invoke('val', 25)  //不太懂,是先将value值设置为25,然后触发change事件,再断言滑块下面会显示数字25.trigger('change')  //拿到滑块的值,触发change事件.get('input[type=range]').siblings('p') //同级别的p元素(兄弟姐妹元素).should('have.text', '25')})

2、invoke(‘text’)
在这里插入图片描述

 it('.should() - make an assertion about the current subject', () => {// https://on.cypress.io/shouldcy.get('.assertion-table').find('tbody tr:last')  //最后一行.should('have.class', 'success').find('td').first()// checking the text of the <td> element in various ways检查td元素的文本.should('have.text', 'Column content').should('contain', 'Column content').should('have.html', 'Column content')// chai-jquery uses "is()" to check if element matches selector.should('match', 'td')// to match text content against a regular expression// first need to invoke jQuery method text()// and then match using regular expression.invoke('text')//先调用jQuery的text方法.should('match', /column content/i)

3、invoke(‘show’)
在这里插入图片描述

 it('.invoke() - invoke a function on the current subject', () => {// our div is hidden in our script.js// $('.connectors-div').hide()cy.get('.connectors-div').should('be.hidden')// https://on.cypress.io/invoke// call the jquery method 'show' on the 'div.container'cy.get('.connectors-div').invoke('show')cy.get('.connectors-div').should('be.visible')})

在这里插入图片描述

it('invokes a callback function with the current subject', () => {// https://on.cypress.io/thency.get('.connectors-list > li').then(($lis) => {  //回调函数function($lis)=>{}expect($lis, '3 items').to.have.length(3)expect($lis.eq(0), 'first item').to.contain('Walk the dog')expect($lis.eq(1), 'second item').to.contain('Feed the cat')expect($lis.eq(2), 'third item').to.contain('Write JavaScript')})})

4、invoke(‘attr’, ‘data-test-id’)
5、invoke(‘css’, ‘position’)

在这里插入图片描述

// 'cy.get()' yields jQuery object, you can get its attribute// by invoking `.attr()` methodcy.get('[data-test-id="test-example"]').invoke('attr', 'data-test-id').should('equal', 'test-example')// or you can get element's CSS propertycy.get('[data-test-id="test-example"]').invoke('css', 'position').should('equal', 'static')//???从哪里判断是static的呢,f12里面怎么看,对于css样式这块的断言确实搞不怎么清楚

这篇关于invoke()到底是个什么方法???的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/798636

相关文章

Linux系统中查询JDK安装目录的几种常用方法

《Linux系统中查询JDK安装目录的几种常用方法》:本文主要介绍Linux系统中查询JDK安装目录的几种常用方法,方法分别是通过update-alternatives、Java命令、环境变量及目... 目录方法 1:通过update-alternatives查询(推荐)方法 2:检查所有已安装的 JDK方

SQL Server安装时候没有中文选项的解决方法

《SQLServer安装时候没有中文选项的解决方法》用户安装SQLServer时界面全英文,无中文选项,通过修改安装设置中的国家或地区为中文中国,重启安装程序后界面恢复中文,解决了问题,对SQLSe... 你是不是在安装SQL Server时候发现安装界面和别人不同,并且无论如何都没有中文选项?这个问题也

Java Thread中join方法使用举例详解

《JavaThread中join方法使用举例详解》JavaThread中join()方法主要是让调用改方法的thread完成run方法里面的东西后,在执行join()方法后面的代码,这篇文章主要介绍... 目录前言1.join()方法的定义和作用2.join()方法的三个重载版本3.join()方法的工作原

在MySQL中实现冷热数据分离的方法及使用场景底层原理解析

《在MySQL中实现冷热数据分离的方法及使用场景底层原理解析》MySQL冷热数据分离通过分表/分区策略、数据归档和索引优化,将频繁访问的热数据与冷数据分开存储,提升查询效率并降低存储成本,适用于高并发... 目录实现冷热数据分离1. 分表策略2. 使用分区表3. 数据归档与迁移在mysql中实现冷热数据分

Spring Boot从main方法到内嵌Tomcat的全过程(自动化流程)

《SpringBoot从main方法到内嵌Tomcat的全过程(自动化流程)》SpringBoot启动始于main方法,创建SpringApplication实例,初始化上下文,准备环境,刷新容器并... 目录1. 入口:main方法2. SpringApplication初始化2.1 构造阶段3. 运行阶

Olingo分析和实践之ODataImpl详细分析(重要方法详解)

《Olingo分析和实践之ODataImpl详细分析(重要方法详解)》ODataImpl.java是ApacheOlingoOData框架的核心工厂类,负责创建序列化器、反序列化器和处理器等组件,... 目录概述主要职责类结构与继承关系核心功能分析1. 序列化器管理2. 反序列化器管理3. 处理器管理重要方

Python错误AttributeError: 'NoneType' object has no attribute问题的彻底解决方法

《Python错误AttributeError:NoneTypeobjecthasnoattribute问题的彻底解决方法》在Python项目开发和调试过程中,经常会碰到这样一个异常信息... 目录问题背景与概述错误解读:AttributeError: 'NoneType' object has no at

postgresql使用UUID函数的方法

《postgresql使用UUID函数的方法》本文给大家介绍postgresql使用UUID函数的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录PostgreSQL有两种生成uuid的方法。可以先通过sql查看是否已安装扩展函数,和可以安装的扩展函数

Java中Arrays类和Collections类常用方法示例详解

《Java中Arrays类和Collections类常用方法示例详解》本文总结了Java中Arrays和Collections类的常用方法,涵盖数组填充、排序、搜索、复制、列表转换等操作,帮助开发者高... 目录Arrays.fill()相关用法Arrays.toString()Arrays.sort()A

Nginx安全防护的多种方法

《Nginx安全防护的多种方法》在生产环境中,需要隐藏Nginx的版本号,以避免泄漏Nginx的版本,使攻击者不能针对特定版本进行攻击,下面就来介绍一下Nginx安全防护的方法,感兴趣的可以了解一下... 目录核心安全配置1.编译安装 Nginx2.隐藏版本号3.限制危险请求方法4.请求限制(CC攻击防御)