Skip to content

Latest commit

 

History

History

iterate-over-list-elements

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 

Iterate Over a List of Elements

Test Code: index.js

Tested Page: TestCafe Example

This example shows how to iterate over a list of elements and use their values in assertions.

The tested page includes a list of <input type="checkbox"> elements.

The expected values of the list items and their ids are declared as an array of objects and have the following structure:

[
    {
        id: 'id-of-the-first-checkbox',
        text: 'Text of the first item'
    },
    {
        ...
    }
]

The test clicks each of the list items to to check them. After that, the test uses the Selector.count property to obtain the number of input elements and iterates through the list of these elements in a for loop. Inside the loop, the input's text is compared to the expected value with the t.expect.eql method.

TestCafe API in This Example

  1. Test Structure:
  2. Element Identification and Actions:
  3. Assertion and Evaluation: