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.
- Test Structure:
- Fixture.page Method
- test Function
- Element Identification and Actions:
- Selector Object
- Selector.withExactText Method
- Selector.parent Method
- Selector.child Method
- Selector.nth Method
- Assertion and Evaluation:
- Selector.count Property
- t.expect.eql Method