I have these codes. it uses each() twice. It always returns false even it should be true.
i added two cy.log()
line.
It got these:
isFound value after assignment is:true
isFound value before return: false
verifyRuleInTable(ruleName) {
const table = cy.get('ex-table[data-testid="deployedapis-table"]').shadow().find('div[role="rowgroup"]');
const realTable = table.find('div[role="row"]')
let isFound = false;
realTable.each(($row, rowIndex) => {
cy.wrap($row).find('div span span').each(($column,columnIndex) =>{
if(columnIndex===1){
cy.wrap($column).invoke('text').then((result) => {
if (result.trim() === ruleName.trim()){
isFound = true;
cy.log('isFound value after assignment is:' + isFound)
}
})
}
})
})
cy.log('isFound value before return: ' + isFound)
return isFound ? true : false;
}
then I changed the code to:
verifyPolicyRuleInTable(policyRuleName) {
const table = cy.get('ex-table[data-testid="deployedapis-table"]').shadow().find('div[role="rowgroup"]');
const realTable = table.find('div[role="row"]')
let isFound = false;
realTable.each(($row, rowIndex) => {
cy.wrap($row).find('div span span').each(($column,columnIndex) =>{
if(columnIndex===1){
cy.wrap($column).invoke('text').then((result) => {
if (result.trim() === policyRuleName.trim()){
isFound = true;
}
})
}
})
}).then(() => {
if (isFound) {
cy.log('Value found!');
} else {
cy.log('Value not found!');
}
});
}
this time it prints 'value found' when isFound
is true and 'value not found' when isFound
= false, however, if I replaced cy.log('Value found!')
with return true
, and cy.log('Value not found!')
with return false
, this piece code returns empty.
How could I let me code returns true when isFound===true
, and returns false when isFound===false