小编ole*_*zya的帖子

变量未在 cypress 中定义

我正在使用此代码进行随机选择。但在这段代码的最后,我想保存变量以在测试用例中进一步使用。我这样做了,但出现了错误

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)
Run Code Online (Sandbox Code Playgroud)

alias cypress

0
推荐指数
1
解决办法
802
查看次数

标签 统计

alias ×1

cypress ×1