> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stably.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Testing File Upload and Download Workflows

> Cover file validation, parsing, progress, and download integrity in Playwright tests

File flows break in subtle ways: invalid MIME handling, upload progress issues, parser errors, and corrupted downloads. This guide covers the highest-value Playwright checks.

## Upload Test Pattern

Use deterministic fixture files and assert server-side result, not just UI success toasts.

```ts tests/files/upload.spec.ts theme={null}
import { test, expect } from '@playwright/test';
import path from 'path';

test('uploads CSV successfully', async ({ page }) => {
  await page.goto('/imports');
  const filePath = path.resolve(__dirname, '../fixtures/customers.csv');

  await page.getByLabel('Upload CSV').setInputFiles(filePath);
  await page.getByRole('button', { name: 'Import' }).click();

  await expect(page.getByText('Import complete')).toBeVisible();
  await expect(page.getByText('120 rows processed')).toBeVisible();
});
```

## Download Test Pattern

Validate filename and file size to catch empty or malformed downloads.

```ts tests/files/download.spec.ts theme={null}
import { test, expect } from '@playwright/test';

test('exports report as CSV', async ({ page }) => {
  await page.goto('/reports');

  const [download] = await Promise.all([
    page.waitForEvent('download'),
    page.getByRole('button', { name: 'Export CSV' }).click(),
  ]);

  expect(download.suggestedFilename()).toContain('.csv');
  const filePath = await download.path();
  expect(filePath).toBeTruthy();
});
```

## Validation Cases You Should Not Skip

* Oversized files are rejected with clear error text.
* Invalid type (`.exe`, wrong MIME) is blocked.
* Malformed CSV or JSON shows row-level error details.
* Duplicate uploads are idempotent or clearly prevented.
* Upload cancellation leaves no partial server records.

## Keep Upload Tests Stable

* Avoid random fixture data unless uniqueness is required.
* Use a small fixture for smoke tests and a large one for stress tests.
* Clean up created records by exact IDs after test completion.

## Stably Features to Use for File Workflows

* Store storage credentials, import endpoints, and size limits in [Stably Environments](/stably2/environments).
* Run high-parallel browser coverage on [Stably Cloud](/run-tests/run-tests-on-cloud) for faster feedback.
* Schedule heavier large-file suites with [Scheduled Test Runs](/run-tests/scheduled-runs) during off-hours.
* Route failures to Slack/email with [Alerts & Notifications](/run-tests/alerting) so ingestion breakages are surfaced quickly.
* Use [Stably Test Reporter](/stably/stably-test-reporter) artifacts (traces/screenshots) to debug flaky upload timing and download corruption.
