我是 cypress 的新手,我创建了一个通用函数,它检查 cypress 中的行数并返回计数。我已经使用了for循环,并返回链下的计数。该函数正确计算计数,但如果我在第二个函数下调用,我会得到 undefined 或 null 我 已经定义了一个全局变量,并且在通用函数下面,我试图返回计数 在第二个函数下调用,我在其中得到 rowcount_val未定义
let rowcount_val = 0
function checkrowcount() {
var count = 0;
var val = ""
for (let i = 1; i <= 10; i++) {
cy.get(".rt-tbody>div:nth-child(" + i + ")>div>div:nth-child(1)").then((
e) => {
val = e.text();
if (val.length > 1) {
count++
}
})
}
cy.then(() => {
return cy.log("count*" + count).then(() => {
return count;
})
})
}
When('click on Add button', function() {
cy.then(() …Run Code Online (Sandbox Code Playgroud)