赛普拉斯:在赛普拉斯中分配和访问全局变量

时间:2020-08-24 16:03:56

标签: cypress

我是cypress的新手,我试图设置几个全局变量以用于不同目的。但是,这些变量的范围即使声明为全局变量也不同。我的期望是输出3:0、4和1,我该怎么做?谢谢大家,我的代码如下:

        var totalCouponCredit = []
        var arrayGameCredit = []
        var totalSelectedCredit, userUsedCredit, gameCredit

        describe ('Testing',function(){
        it('Login',function(){
          cy.get('div.row.flex-lg-column.h-100>div:nth-of-type(1)>div>div>h6').then(($selectedCredit)=>{
          //This is the string return "SELECTED CREDITS 0/4", userUsedCredit is 0 and totalSelectedCredit is 4 after split
          totalCouponCredit = $selectedCredit.text().match(/[a-zA-Z]+|[0-9]+(?:\.[0-9]+|)/g)
          userUsedCredit = parseInt(totalCouponCredit[2])
          totalSelectedCredit = parseInt(totalCouponCredit[3])
          cy.get('div.col>p:nth-of-type(1)>span>span').then(($gameCredit)=>{
          //This is the string return "This title is worth 1 credit(s)", gameCredit is 1 after split
            arrayGameCredit = $gameCredit.text().match(/[a-zA-Z]+|[0-9]+(?:\.[0-9]+|)/g)
            gameCredit = parseInt(arrayGameCredit[4])
            cy.log("Out put 1:" + userUsedCredit + " and " + totalSelectedCredit + " and " +gameCredit)                
          })
          cy.log("Out put 2:" + userUsedCredit + " and " + totalSelectedCredit + " and " +gameCredit)
          })
        cy.log("Out put 3:" + userUsedCredit + " and " + totalSelectedCredit + " and " +gameCredit)
        })
})

输出:

Output 1: 0 and 4 and 1
Output 2: 0 and 4 and undefined
Output 3: undefined and undefined and undefined

0 个答案:

没有答案