I am new in cypress, I have created a generic function which is checking the count of rows in cypress and returning the count. I have used for loop, and returning the count under the chain. This function is correctly calculating count but if I call under the second function I am getting as undefined or null I have defined a global variable and below generic function where I am trying to return the count Calling under second function, in which I am getting rowcount_val as undefined
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(() => {
rowcount_val = checkrowcount();
cy.log("rowcountvalue is ******" + rowcount_val)
})
})