The webpage I am testing in Testcafe has got two groups of radio-boxes.
Now I am trying to do the following but the code is not verifying it properly. 1.count the number of total radio-boxes combined from both groups 2. Iterate over this count to find the ticked radio-box + the test text associated with it. (for ex - ticked radio-box element from first group + 'Yes', or ticked radio-box element from second group + 'sample test text')
Can you please help debugging it ?
const radioBox = Selector('.radioBox')
const radioboxCount = await radioBox.count
console.log(await radioboxCount);
//verify if the first group of radio-box is present with 'Yes' selected by default.
for (let count = 0; count < await radioboxCount; count++) {
console.log("Inside Loop");
var radioBoxObject1 = Selector('.radioBox').nth(count).find('label').withText('Yes')
var radioBoxObject2 = Selector('.radioBox').nth(count).find('input').withAttribute('checked')
if((radioBoxObject1.exists) && (radioBoxObject2.exists)){
console.log('service question has been asked correctly'+ count)
}else {
console.log('issue in service question answer')
}
Since there are total 5 radio-boxes and I am checking for 'Yes' radio box, I expect the output to be: Landing Page 5 Inside Loop service question has been asked correctly0
Use await
when you try to check exists
outside the built-in expect
. Otherwise, it returns Promise and Promise is true in the if-else condition.
if((await radioBoxObject1.exists) && (await radioBoxObject2.exists)){