场景描述:当你在做充值操作时,需要校验充值前后账户余额的变化
获取余额,并存入变量accountValue
getAmount(wallet, coin){
cy.get('amount').within(() => {
cy.get('div').invoke('text').then((text) => {
const con = text.split(/\s+/)
cy.wrap(Number((Number(con[0]) * 100).toFixed())).as('accountValue')
})
})
return this
}
再另一个方法内使用,
verifyAmount(operation, amount){
amount = Number((Number(amount) * 100).toFixed())
cy.get('@accountValue').then((a) => {
let finalAmount = a
if(operation == '-') {
finalAmount -= amount
}else{
finalAmount += amount
}
expect(...).to.eq(finalAmount)
})
return this
}
网友评论