如果想从头学起Cypress,可以看下面的系列文章哦
https://www.cnblogs.com/poloyy/category/1768839.html
获取上一条命令结果的属性值
.its(propertyName)
.its(propertyName, options)
propertyName:索引、属性名、要获取的嵌套属性名称
options:log、timeout
属性值
cy.wrap({ width: '50' }).its('width') // 获取宽度属性
cy.window().its('sessionStorage') // 获取 sessionStorage 属性
cy.its('window') // 不能链接在 cy 后面
cy.clearCookies().its('length') // clearCookies 并不返回对象
cy.wrap({age: 52}).its('age').should('eq', 52) // true
cy.wrap(['polo', 'yy']).its(1).should('eq', 'yy')
cy
.get('ul li')
.its('length')
.should('be.gt',4)
cy
.url()
.its('length')
.should('be.gt', 20)
const fn = () => {
return 42
}
cy.wrap({getNum: fn}).its('getNum').should('be.a', 'function')
返回的是函数对象本身,而不是 return 的值
const user = {
contacts: {
work: {
name: 'Kamil'
}
}
}
cy.wrap(user).its('contacts.work.name').should('eq', 'Kamil') // true
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有