JavaScript · Cypress
Digital Rights Management with Cypress
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 Cypress suite
A working starting point that finds elements every way Cypress 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.
Cypress runs inside the browser, so it only supports JavaScript and TypeScript — there is no Python, Java or C# version of Cypress. For those languages, see Selenium or Playwright.
// Uses the getByTestId custom command from the Cypress setup (cypress/support/commands.js).
// Locators in this suite: cy.contains ×8 · #id ×4 · [name] ×5 · [placeholder] ×1 · getByTestId ×12
describe('KeyVault DRM — digital rights management', () => {
it('issues a Widevine token and redeems it', () => {
cy.visit('/apps/drm');
cy.get('#drm-email').type('admin@keyvault.dev');
cy.get('[name="drm-password"]').type('Drm@123');
cy.contains('button', 'Continue').click();
cy.getByTestId('drm-otp').type('135790');
cy.contains('button', 'Verify & sign in').click();
cy.location('pathname').should('include', '/apps/drm/dashboard');
cy.getByTestId('setup-hint').should('be.visible');
// Create an API key — its secret is shown only once
cy.contains('a', 'Keys').click();
cy.get('[placeholder="e.g. Storefront production"]').type('Storefront');
cy.getByTestId('create-key').click();
cy.getByTestId('secret-value').should('contain', 'kv_live_');
cy.getByTestId('secret-done').click();
// Issue a Widevine token bound to one device, requiring HDCP
cy.contains('a', 'Tokens').click();
cy.contains('button', 'Widevine').click();
cy.get('#tk-title').select('t1');
cy.get('[name="tk-user"]').type('user-42');
cy.get('#tk-device').type('a1b2c3d4e5f60718');
cy.get('#tk-hdcp').check();
cy.contains('button', 'Generate token').click();
cy.getByTestId('token-id').should('contain', 'TKN-');
cy.getByTestId('token-balance').should('contain', '499');
// Redeem on an HDCP-capable phone, then on a desktop without HDCP
cy.contains('a', 'Simulator').click();
cy.get('[name="sim-device"]').select('android-phone');
cy.get('[name="sim-device-id"]').type('a1b2c3d4e5f60718');
cy.getByTestId('redeem-token').click();
cy.getByTestId('sim-status').should('contain', 'Licence granted');
cy.getByTestId('licence-id').should('contain', 'LIC-');
cy.get('[name="sim-device"]').select('chrome-desktop');
cy.getByTestId('redeem-token').click();
cy.getByTestId('sim-reason').should('contain', 'KV-420');
cy.contains('a', 'Reports').click();
cy.getByTestId('report-row').eq(0).should('contain', 'KV-420');
});
});