27. Data-Driven Testing & Parameterized Scenarios

Parameterized Testing with JavaScript Arrays

import { test, expect } from "@playwright/test";

const searchQueries = [
{ term: "Playwright", expectedCount: 10 },
{ term: "JavaScript", expectedCount: 20 },
{ term: "Automation", expectedCount: 15 },
];

for (const { term, expectedCount } of searchQueries) {
test(search for "${term}" returns at least ${expectedCount} results, async ({ page }) => {
await page.goto("/search");
await page.getByPlaceholder("Search").fill(term);
await page.keyboard.press("Enter");
await expect(page.locator(".search-result")).toHaveCount(expectedCount);
});
}

Task

  • Implement generateCartesianProduct:
  • 1. Accept listA and listB arrays.
  • 2. Return array of [a, b] pairs for every combination.
πŸ’‘Common doubts
Did you like the problem?
Lesson 27 of 35
JavaScript
Loading code editor…
Next