← Back to library
Playwrightassertionsintermediatev1.30+
Assert all list items match a condition
Iterate over every matched element using locator.all() and assert each one.
1test('every search result contains the keyword', async ({ page }) => {
2 await page.goto('/search?q=cypress');
3
4 const items = page.locator('[data-testid="result-item"]');
5 await expect(items).not.toHaveCount(0);
6
7 // locator.all() resolves the locator to an array of elements
8 for (const item of await items.all()) {
9 await expect(item).toContainText(/cypress/i);
10 }
11});#list#all#each#contains#loop