Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cypress:在Cypress中分配和访问全局变量_Cypress - Fatal编程技术网

Cypress:在Cypress中分配和访问全局变量

Cypress:在Cypress中分配和访问全局变量,cypress,Cypress,我是cypress的新手,我尝试设置几个全局变量以用于不同的目的。然而,这些变量的范围是不同的,即使它们被声明为全局变量。我的期望是输出3:0和4:1,我怎么能做到呢?谢谢大家,我的代码如下: var totalCouponCredit = [] var arrayGameCredit = [] var totalSelectedCredit, userUsedCredit, gameCredit describe ('Testi

我是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