Web Tables Loops | Bondar Academy
Course: Playwright UI Testing with TypeScript
Module: Mastering UI Elements
Instructor: Artem Bondar
Lesson Summary
In this lesson, we focus on looping through table rows to perform validation of each value. The example involves searching for specific ages in a table and ensuring the output matches the expected results. Key Concepts Search Functionality: Users can search by age, e.g., searching for age 30 yields one result, while age 20 yields five results. Validation: The goal is to ensure that the output only contains rows with the searched age. Implementation Steps Identify Test Data: Create an array of ages to test, including valid and invalid cases (e.g., 20, 30, 40, 200). Create a Loop: Use a for loop to iterate through each age value. Input Age: Type the age into the input field using the appropriate locator. Get Table Rows: Use a locator to fetch all rows from the table body. Validate Rows: For each row, check the last column's value against the expected age. Handling Delays To address timing issues between input and table updates, introduce a delay using: await page.waitForTimeout(500); Conditional Assertions Implement conditional logic to handle cases like searching for age 200, which should return a "no data found" message: if (age === 200) { expect(...).toContain('no data found'); } In summary, this lesson demonstrates how to loop through table rows, validate search results, and handle dynamic content updates effectively.