TypeScript · @playwright/test
Digital Rights Management with Playwright
Sign in with OTP and roles, create API keys (secret shown once), register titles with 32-hex content keys, issue Widevine, PlayReady and FairPlay licence tokens with expiry, rental, device-binding and HDCP rules, then redeem them on simulated devices and audit every grant or denial.
App under test
🔐 KeyVault DRM
- URL
- /apps/drm
- Admin
- admin@keyvault.dev / Drm@123
- OTP
- 135790
- Other roles
- ops@ · viewer@keyvault.dev
- Key format
- 32 hex · device 16 hex
Scenarios to automate
Work top to bottom — each one adds a new technique.
- 1
Two-step login & lockout
BeginnerWrong password shows attempts left in drm-login-error; the 3rd failure locks the form (drm-unlock resets). Correct password leads to drm-otp-form; OTP 135790 signs in.
- 2
Role-based access
Intermediateops@ and viewer@ see access-denied on API keys and Account; viewer@ gets tokens-readonly and a disabled generate-token button.
- 3
Show-once secrets
Intermediatecreate-key opens secret-modal with secret-value (kv_live_…); after secret-done only key-masked-<id> (last 4 chars) remains. revoke-<id> needs confirm-revoke.
- 4
Hex validation
Beginnersave-title with a 31-char or non-hex key shows error-title-key (KV-201); generate-key fills 32 hex and key-length shows 32 / 32.
- 5
Token rules
AdvancedExpiry +2592001 fails with KV-204 (max 30 days); play duration above the rental period fails with KV-205; a 15-char device ID fails with KV-202.
- 6
Account-level blockers
IntermediateNo active API key → token-error KV-101; FairPlay disabled in Production → KV-301; balance 0 (drain-balance) → KV-402.
- 7
Licence decisions
AdvancedIn the simulator, a wrong device ID gives KV-403, HDCP on Chrome desktop gives KV-420, Widevine level 5 on a phone gives KV-421, and moving sim-offset past expiry gives KV-410.
- 8
Reports & export
BeginnerFilter report-drm / report-result, search, walk report-next until disabled, and export-csv downloads keyvault-licences.csv.
Sample Playwright suite
A working starting point that finds elements every way Playwright can — by role, label, text, id, name, CSS, XPath and data-testid — so you practice them all. Pick your language, switch to data-testid only to compare, or try your own in the Locator Playground.
import { test, expect } from '@playwright/test';
// playwright.config.ts → use: { baseURL: 'https://www.practiceqaautomation.com' }
// Locators in this suite: getByRole ×4 · getByLabel ×5 · getByPlaceholder ×1 · CSS ×4 · XPath ×4 · getByTestId ×12
test('issues a Widevine token and redeems it', async ({ page }) => {
await page.goto('/apps/drm');
await page.getByLabel('Work email').fill('admin@keyvault.dev');
await page.locator('#drm-password').fill('Drm@123');
await page.getByRole('button', { name: 'Continue' }).click();
await page.getByTestId('drm-otp').fill('135790');
await page.locator('xpath=//button[normalize-space()="Verify & sign in"]').click();
await expect(page).toHaveURL(/\/apps\/drm\/dashboard/);
await expect(page.getByTestId('setup-hint')).toBeVisible();
// Create an API key — its secret is shown only once
await page.getByRole('link', { name: 'Keys', exact: true }).click();
await page.getByPlaceholder('e.g. Storefront production', { exact: true }).fill('Storefront');
await page.getByTestId('create-key').click();
await expect(page.getByTestId('secret-value')).toContainText('kv_live_');
await page.getByTestId('secret-done').click();
// Issue a Widevine token bound to one device, requiring HDCP
await page.locator('xpath=//a[normalize-space()="Tokens"]').click();
await page.getByRole('button', { name: 'Widevine' }).click();
await page.getByLabel('Title').selectOption('t1');
await page.locator('#tk-user').fill('user-42');
await page.getByLabel('Bind to device ID (optional)').fill('a1b2c3d4e5f60718');
await page.locator('#tk-hdcp').check();
await page.locator('xpath=//button[normalize-space()="Generate token"]').click();
await expect(page.getByTestId('token-id')).toContainText('TKN-');
await expect(page.getByTestId('token-balance')).toContainText('499');
// Redeem on an HDCP-capable phone, then on a desktop without HDCP
await page.getByRole('link', { name: 'Simulator' }).click();
await page.getByLabel('Device', { exact: true }).selectOption('android-phone');
await page.locator('#sim-device-id').fill('a1b2c3d4e5f60718');
await page.getByTestId('redeem-token').click();
await expect(page.getByTestId('sim-status')).toContainText('Licence granted');
await expect(page.getByTestId('licence-id')).toContainText('LIC-');
await page.getByLabel('Device', { exact: true }).selectOption('chrome-desktop');
await page.getByTestId('redeem-token').click();
await expect(page.getByTestId('sim-reason')).toContainText('KV-420');
await page.locator('xpath=//a[normalize-space()="Reports"]').click();
await expect(page.getByTestId('report-row').nth(0)).toContainText('KV-420');
});