2. Working with Collections, Objects & JSON

Collections in Test Automation

const testUsers = [
  { id: 1, role: "admin", email: "admin@targetqa.com" },
  { id: 2, role: "tester", email: "tester@targetqa.com" },
];

// Extract all emails with map:
const emails = testUsers.map(u => u.email);

// Filter by role:
const admins = testUsers.filter(u => u.role === "admin");

// Object destructuring (used extensively in Playwright fixtures):
const { page, context } = testArgs;

Task

  • Implement filterActiveUsers:
  • 1. Accept users array containing { id, name, isActive }.
  • 2. Return only the users where isActive is true.
πŸ’‘Common doubts
Did you like the problem?
Lesson 2 of 18
JavaScript
Loading code editor…
Next