API Versioning Testing: How to Test v1, v2, and Deprecated Endpoints Simultaneously
Your API has v1 and v2 running simultaneously. v1 is deprecated but still used by 30% of clients. Here is how to test both versions without maintaining duplicate test suites.
π Want to master this with real projects? Join the Playwright Automation Mastery course at The Testing Academy.
Contents
Versioned Test Structure
// Shared test logic, parameterized by version
const versions = ['v1', 'v2'];
for (const v of versions) {
test.describe('GET /api/' + v + '/users', () => {
test('returns user list', async ({ request }) => {
const res = await request.get('/api/' + v + '/users');
expect(res.ok()).toBeTruthy();
const body = await res.json();
expect(body.users).toBeInstanceOf(Array);
});
});
}
// v2-only features
test('v2 supports pagination', async ({ request }) => {
const res = await request.get('/api/v2/users?page=1&limit=10');
const body = await res.json();
expect(body.pagination).toBeDefined();
expect(body.pagination.page).toBe(1);
});
// v1 deprecation header check
test('v1 returns deprecation warning', async ({ request }) => {
const res = await request.get('/api/v1/users');
expect(res.headers()['deprecation']).toBeDefined();
expect(res.headers()['sunset']).toBeDefined();
});
π Level Up Your Playwright
From locators to CI pipelines β build a production-grade Playwright + TypeScript framework step by step.
Backward Compatibility Testing
test('v2 response is superset of v1', async ({ request }) => {
const v1 = await (await request.get('/api/v1/users/1')).json();
const v2 = await (await request.get('/api/v2/users/1')).json();
// All v1 fields must exist in v2
for (const key of Object.keys(v1)) {
expect(v2).toHaveProperty(key);
}
});
π Master Playwright End to End
Join hundreds of SDETs building real automation frameworks. Lifetime access, hands-on projects, and a job-ready portfolio.
