Skip to main content
File Operations

Download CSV File

DownloadValidateEasy

What you will learn

  • Assert Content-Disposition header AND filename โ€” downloading with wrong filename breaks user expectations
  • Streaming downloads must be readable incrementally โ€” loading the full body defeats the point AND OOMs on large files
  • Cancel mid-download: the server must release the underlying resource (DB connection, S3 stream) within seconds, not hold it

Description

Download a CSV file and verify its Content-Type header and data structure. Learn to parse CSV and validate the content.

Test Scenario

// Playwright: Download and verify CSV
const response = await request.get('/api/v1/files/download?format=csv&rows=10');

// Check headers
expect(response.headers()['content-type']).toContain('text/csv');
expect(response.headers()['content-disposition']).toContain('filename=');

// Parse CSV
const csv = await response.text();
const lines = csv.trim().split('\n');
expect(lines[0]).toBe('id,name,email,role,createdAt');
expect(lines.length).toBe(11); // header + 10 rows
Endpoint/api/v1/files/download?format=csv&rows=10&type=users

Testing Tips

  • โ€ขCheck Content-Type is text/csv
  • โ€ขVerify Content-Disposition contains filename
  • โ€ขParse CSV and validate header row
  • โ€ขCheck that data rows match expected count
// Playwright API Testing - File Operations
import { test, expect } from '@playwright/test';
test('File download', async ({ request }) => {
const response = await request.get('/api/files/download/report.pdf');
expect(response.ok()).toBeTruthy();
expect(response.headers()['content-type']).toContain('application/pdf');
const buffer = await response.body();
expect(buffer.length).toBeGreaterThan(0);
});

Challenge ID: download-csv

2 frameworks available

API Playground

Send requests and inspect responses

Endpoint: /api/v1/files/download?format=csv&rows=10&type=users

Press Enter to send