如果想从头学起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
原文:https://www.cnblogs.com/poloyy/p/13686431.html