Five Field Dashboards Captured with the Superadmin Face
Screenshot manuals recorded five field dashboards as the superadmin view; per-test identity moved to session cookies inside one context.
TL;DR
The screenshot manual showed one dashboard for all five field roles, but four dashboards actually differ structurally. Fix: keep one superadmin storageState as seed, then each capture test logs in via API and overwrites cookies on the same context. New roles now need just one capture test plus a roleItemHtml mapping entry.
While flipping through the screenshot manual produced by the generator for a role-based admin application, the Dashboard page kept repeating with the same face. The statistics cards were identical in every section of the manual, the numbers matched, and not a single element marked that page as belonging to a field account. Yet the five field accounts the QA team used clearly landed on different dashboards in a real login: the statistics nouns differ per field, there is a "My field" scope toggle, and one "Manage <module>" button that only appears for the related role.
Five roles documented with one face. The manual was wrong for four of them.
First guess: one more auth state file per role
My first assumption was that the screenshot capture pattern needed one additional authentication state file per field, complete with its own session cookies. Technically that can run, but the consequences show up immediately. Five files mean five login fixtures running in parallel during setup, and every file stores sensitive cookies and headers that must never enter the repository, as the Playwright authentication documentation warns [1]. The balance between architectural tidiness and security risk did not lean that way.
One state file shared across all tests is actually the default identity for a single context, not a per-test contract.
What actually happens in the browser context
Playwright runs every test inside an isolated browser context, and a context is an independent browser session that can carry pre-existing authentication state [2]. The key to the contract sits in addCookies: cookies installed through a context apply to every page in that context. A test's identity can therefore be swapped without touching any auth state file at all.
That detail changed the capture design. The earlier assumption was that fields differ only in data, so the same page just needed recapturing with a different account. After a closer look, each field's dashboard differs structurally, not only in content: the Tourism badge reads 246 while the Sports Facilities badge reads 169, and the scope element plus call-to-action exist only in some roles. Capturing "same page, different data" would have produced a manual still wrong for four fields.
API login in the same context, capture per field
The pattern used: one storageState as the superadmin session seed, then each capture test performs a login through the API on the same context, so the session cookies overwrite the seed identity only for the test currently running.
import { test, expect } from '@playwright/test';
test('capture dashboard bidang', async ({ page, context }) => {
const res = await context.request.post('https://example.com/api/login', {
data: {
email: '<QA_EMAIL>',
password: process.env.QA_PASSWORD ?? '<QA_PASSWORD>',
},
});
test.skip(!res.ok(), 'login gagal, capture bidang dilewati');
const session = (await context.cookies('https://example.com'))
.find((c) => c.name === 'session');
expect(session?.value).toBeTruthy();
await page.goto('/dashboard');
await expect(page.locator('[data-testid="dashboard-bidang-badge"]')).toBeVisible();
await page.screenshot({ path: 'manual/dashboard-bidang.png', fullPage: true });
await page.locator('[data-testid="popular-scope-toggle"]')
.screenshot({ path: 'manual/scope-toggle.png' });
});
Five capture tests now log in as the QA account for each field, with a password overridable through an environment variable and account details sourced from the development database inventory. If login fails, the test is skipped so the manual build keeps running; an authentication failure is no reason to shut down the whole pipeline. Each capture produces two images: one full-page screenshot, one area shot of the popular scope toggle serving as evidence of each field's scope.
On the generator side, roleItemHtml maps the Dashboard menu to the dashboard group owned by that role itself, and the dashboard-<field> entry becomes the first item in each field section. The superadmin keeps the ALL dashboard group. Field role views also no longer display "Other fields", following the owner's direction because that catalog is read-only, so the documentation reflects what the account actually sees.
Proof in the manifest and the badges
The manual manifest grew from 24 to 29 groups: five new dashboard groups, one per field, plus section structure placing them first. Three checks close this change. The Tourism and Sports Facilities dashboard badges must show different numbers, 246 versus 169. Each role's role view and access card must point at the correct dashboard group, not the ALL group. The badge element assertion must pass before the screenshot is taken, so empty images fail early.
The decision was simple and I kept it: one auth state file stays as the seed, the identity contract moves to per-test cookies. A new role no longer means a new login fixture, just one added capture test and one mapping entry in roleItemHtml.
Sources
1. Playwright — Authentication (authentication state, storageState, sensitive cookie storage), accessed 8 November 2026.
2. Playwright — BrowserContext (independent browser sessions, addCookies for every page in a context), accessed 8 November 2026.