【发布时间】:2022-07-22 18:27:21
【问题描述】:
我正在使用此代码进行随机选择。但在这段代码的最后,我想保存变量以在测试用例中进一步使用。我这样做了,但我得到了错误
cy.get('div.cdk-virtual-scroll-content-wrapper nz-option-item') // we get the select/option by finding the select by class
.then(listing => {
const randomNumber = getRandomInt(0, listing.length-1); //generate a rendom number between 0 and length-1. In this case 0,1,2
cy.get('div.cdk-virtual-scroll-content-wrapper nz-option-item').eq(randomNumber).then(($select) => { //choose an option randomly
const text = $select.text() //get the option's text. For ex. "A"
cy.get('div.cdk-virtual-scroll-content-wrapper').contains(text).click() // select the option on UI
let region = text;
cy.wrap(region).as('region')
});
})
cy.log(region)
【问题讨论】:
-
你不能在
cy.wrap之后立即调用cy.log- 不管怎样,将来cy.get都会调用它。
标签: cypress