TestCafe loop over elements and check if class exists within Set

Viewed 403

I have a table with a column of icons. Each Icon has a class of "test" and then "test" + [some rating]. The rating could be A, B, C, XX, YY. I'd like to select the group of icons and loop over them, pop off the last class (the one with the rating) and then expect that my Set of classConsts contains the class in question. I've done a bunch of research but can only find examples of interacting with each of the elements, I'm not sure what I'm doing wrong when trying to check the classes on each instead. Any help is appreciated, thanks.

The below code blows up when i call mrArray.nth saying it's not a function (sorry its a bit messy, had to change some variable names around)

test('Sers are verified', async t => {
    const IconArr = Selector('#testtable .test');
    var count = await IconArr().count;
    var myArray = await IconArr();

    const classConsts = ["testClassA", "testClassB", "testClassC", "testClassXX", "testClassYY"]

    let mySet = new Set(classConsts);

    for(let i = 1; i <= count; i++){
        console.log(mySet.has(myArray.nth(i).classNames.pop()));
    };
});
1 Answers

myArray is no longer a Selector object after you execute it as an asynchronous function. Please refer to the following help article for more information DOMNodeState.

Also, the index starts with 0, not 1. Your code may look as follows:

for(let i = 0; i \< count; i++){
   let classes = await IconArr().nth(i).classNames;
   console.log(mySet.has(classes.pop()));
};

You can always debug your test cases to see what goes wrong:

https://devexpress.github.io/testcafe/documentation/recipes/debugging/chrome-dev-tools.html

Related