当前位置: 首页 > news >正文

wrap:包装

1、wrap(对象)调用对象的函数,来产生新的值。

const getName = () => {return 'Jane Lane'
}cy.wrap({ name: getName }).invoke('name').should('eq', 'Jane Lane') // true

wrap(对象),断言对象的属性、属性包含的值

it('cy.wrap() - wrap an object', () => {// https://on.cypress.io/wrapcy.wrap({ foo: 'bar' }).should('have.property', 'foo').and('include', 'bar')})

2、wrap(数组名称)

 it('.spread() - spread an array as individual args to callback function', () => {// https://on.cypress.io/spread  //传递一个数组(作为单个函数)给回调函数const arr = ['foo', 'bar', 'baz']cy.wrap(arr).spread((foo, bar, baz) => {  //wrap包装了(接收了)一个对象(数组),然后调用数组里面的值expect(foo).to.eq('foo')expect(bar).to.eq('bar')expect(baz).to.eq('baz')})})

3、wrap(数值)

it('yields the returned value to the next command', () => {//为下一个命令生成返回值cy.wrap(1).then((num) => {expect(num).to.equal(1)return 2  //返回值2}).then((num) => {expect(num).to.equal(2)})})it('yields the original subject without return', () => {cy.wrap(1).then((num) => {expect(num).to.equal(1)// note that nothing is returned from this callback这个回调中没有东西返回}).then((num) => {// this callback receives the original unchanged value 1  这俄格回调接受没有改变的原始值1expect(num).to.equal(1)})})it('yields the value yielded by the last Cypress command inside', () => {cy.wrap(1).then((num) => {expect(num).to.equal(1)// note how we run a Cypress command  我们怎样允许命令// the result yielded by this Cypress command  通过命令生成结果// will be passed to the second ".then" 将通过第二个.thency.wrap(2)}).then((num) => {// this callback receives the value yielded by "cy.wrap(2)"  这个回调接受通过 "cy.wrap(2)"生成的值expect(num).to.equal(2)})})

4、wrap(Cypress.spec)包一个用例文件
运行的时候看一下f12里面是否有这个效果:有,选中断言时,console里面有对应的keys内容

it('Get current spec information', () => {// https://on.cypress.io/spec// wrap the object so we can inspect it easily by clicking in the command log  返回测试文件的属性/规格信息cy.wrap(Cypress.spec).should('include.keys', ['name', 'relative', 'absolute'])})

5、wrap(this.example)包当前测试套件中的名称为example的json文件

/// <reference types="cypress" />/// JSON fixture file can be loaded directly using
// the built-in JavaScript bundler
const requiredExample = require('../../fixtures/example')context('Files', () => {beforeEach(() => {cy.visit('https://example.cypress.io/commands/files')// load example.json fixture file and store 加载example.json文件并且存储在测试context对象里面// in the test context objectcy.fixture('example.json').as('example')})it('cy.fixture() or require - load a fixture', function () {// we are inside the "function () { ... }"// callback and can use test context object "this"    我们里面的方法调用可以使用context对象this// "this.example" was loaded in "beforeEach" function callback         this.example在“beforeEach”方法回调里面被加载expect(this.example, 'fixture in the test context').to.deep.equal(requiredExample)// or use "cy.wrap" and "should('deep.equal', ...)" assertioncy.wrap(this.example).should('deep.equal', requiredExample)})
})

6、在对象里装个监控,调用对象时再断言这个监控被调用了

 it('cy.spy() - wrap a method in a spy', () => {// https://on.cypress.io/spy  在监控中包了一个方法cy.visit('https://example.cypress.io/commands/spies-stubs-clocks')const obj = {foo () {},}const spy = cy.spy(obj, 'foo').as('anyArgs')  //监控了一个对象,上方对象里面有个方法obj.foo()  //调用对象的方法时,下面断言监控被调用了//监控函数运行情况expect(spy).to.be.called})

7、包住li标签,断言里面的属性

 it('Cypress.$ - call a jQuery method', () => {// https://on.cypress.io/$let $li = Cypress.$('.utility-jquery li:first')cy.wrap($li).should('not.have.class', 'active').click().should('have.class', 'active')})

相关文章:

  • C#版开源免费的Bouncy Castle密码库
  • SA3D:基于 NeRF 的三维场景分割方法
  • k8s+wordpress+zabbix+elastic+filebeat+kibana服务搭建以及测试
  • APK漏洞扫描工具
  • 高可用篇_A Docker容器化技术_V 基于DockerCompose实现容器编排
  • MyBatis拦截器四种类型和自定义拦截器的使用流程
  • 黑豹程序员-java按限定范围产生多个随机数
  • BUUCTF-----[SWPU2019]Web1
  • C# 协程的使用
  • DVWA靶场-暴力破解
  • 【Java EE】线程安全的集合类
  • STM32点亮LED灯与蜂鸣器发声
  • .net6Api后台+uniapp导出Excel
  • @Autowired 与@Resource的区别
  • <机器学习初识>——《机器学习》
  • Promise面试题,控制异步流程
  • SpringCloud集成分布式事务LCN (一)
  • SQL 难点解决:记录的引用
  • vue 个人积累(使用工具,组件)
  • Vue 重置组件到初始状态
  • 成为一名优秀的Developer的书单
  • 动态规划入门(以爬楼梯为例)
  • 关于字符编码你应该知道的事情
  • 欢迎参加第二届中国游戏开发者大会
  • 让你成为前端,后端或全栈开发程序员的进阶指南,一门学到老的技术
  • 微信端页面使用-webkit-box和绝对定位时,元素上移的问题
  • 微信小程序实战练习(仿五洲到家微信版)
  • Oracle Portal 11g Diagnostics using Remote Diagnostic Agent (RDA) [ID 1059805.
  • MPAndroidChart 教程:Y轴 YAxis
  • 第二十章:异步和文件I/O.(二十三)
  • 如何正确理解,内页权重高于首页?
  • ​软考-高级-信息系统项目管理师教程 第四版【第19章-配置与变更管理-思维导图】​
  • #### go map 底层结构 ####
  • #《AI中文版》V3 第 1 章 概述
  • #pragma multi_compile #pragma shader_feature
  • #周末课堂# 【Linux + JVM + Mysql高级性能优化班】(火热报名中~~~)
  • (02)Cartographer源码无死角解析-(03) 新数据运行与地图保存、加载地图启动仅定位模式
  • (4)事件处理——(7)简单事件(Simple events)
  • (Matalb分类预测)GA-BP遗传算法优化BP神经网络的多维分类预测
  • (附源码)springboot青少年公共卫生教育平台 毕业设计 643214
  • (论文阅读40-45)图像描述1
  • (原創) 如何讓IE7按第二次Ctrl + Tab時,回到原來的索引標籤? (Web) (IE) (OS) (Windows)...
  • (原創) 未来三学期想要修的课 (日記)
  • (转)Java socket中关闭IO流后,发生什么事?(以关闭输出流为例) .
  • (转)微软牛津计划介绍——屌爆了的自然数据处理解决方案(人脸/语音识别,计算机视觉与语言理解)...
  • (转载)微软数据挖掘算法:Microsoft 时序算法(5)
  • ***通过什么方式***网吧
  • .NET Compact Framework 3.5 支持 WCF 的子集
  • .Net IE10 _doPostBack 未定义
  • .NET/C# 反射的的性能数据,以及高性能开发建议(反射获取 Attribute 和反射调用方法)
  • .net生成的类,跨工程调用显示注释
  • /proc/vmstat 详解
  • @DataRedisTest测试redis从未如此丝滑
  • @selector(..)警告提示
  • [ 手记 ] 关于tomcat开机启动设置问题