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
解决方案
推荐阅读
- html - 不透明的 CSS 动画不适用于 safari,但适用于谷歌浏览器
- c++ - 如何打开一个文本文件
- python - 如何将excel日期时间作为浮点数而不是xlwings中的'datetime.datetime'?
- python - 如何在 BeautifulSoup 上获得多个具有相同 html 标签的项目
- amazon-web-services - 如何获取通过 Amazon SES 发送的电子邮件的状态
- elasticsearch - 需要一个在预定时间前 5 分钟开始的弹性搜索查询过滤器范围
- java - 为什么原子不知道周期
- r - 在 R 中将 Excel 文件批量转换为 PDF
- javascript - 使用从上一页传入的输入值在页面加载时过滤列表
- excel - 如果单元格 A 中的数字发生变化,则增加新单元格中的值