Modern QA2026Pattern 4: Data Extraction and Verification — tiles
Log inJoin
79 / 168 · 01 Agent Skills for Browser Automation · Test Patterns for AI-Driven Browser Automation← prev⊞ allnext →☰ Read as one page

11.5Pattern 4: Data Extraction and Verification

Extract structured data from the page and verify against expected values.

Example: Dashboard Metrics

playwright-cli goto https://app.example.com/dashboard
playwright-cli eval "JSON.stringify({
  revenue: document.querySelector('.metric-revenue').textContent,
  users: document.querySelector('.metric-users').textContent,
  orders: document.querySelector('.metric-orders').textContent
})"
# → {"revenue": "$45,230", "users": "1,234", "orders": "567"}

Example: Table Data

playwright-cli goto https://app.example.com/users
playwright-cli eval "JSON.stringify(
  [...document.querySelectorAll('table tbody tr')].map(row => ({
    name: row.cells[0].textContent,
    email: row.cells[1].textContent,
    role: row.cells[2].textContent
  }))
)"
# → [{"name": "Alice", "email": "alice@test.com", "role": "Admin"}, ...]

eval is the escape hatch: when you need data rather than interaction, one JavaScript expression beats parsing a snapshot. (Inside eval you write ordinary DOM selectors — refs are for CLI interaction commands.)

Agent's Added Value

The agent can:

  • Parse the JSON output
  • Compare against expected values from a database or API
  • Identify discrepancies and report them meaningfully