Playwright File Upload Testing Guide with setInputFiles and FileChooser
Guide to Playwright file upload testing with setInputFiles, file chooser events, hidden inputs, and CI-safe validation patterns.
Teams searching playwright file upload are usually working on flows that matter to the business: resumes, invoices, profile images, import CSVs, compliance documents, and support attachments. Upload tests need to be reliable because they often sit on critical paths and generate real backend side effects.
Key Takeaways
- Use
setInputFiles()when the input is directly addressable. - Use the file chooser event for custom buttons that trigger native file selection.
- Keep test fixtures small and deterministic so uploads stay CI-friendly.
- Assert on both UI confirmation and the downstream success signal.
Why This Topic Matters in 2026
- Upload flows combine browser interaction, validation messages, file system access, and backend processing.
- Modern apps often hide the file input behind a styled button, which means you need both direct input and file chooser strategies.
- The Playwright CLI skill can reproduce upload behavior quickly when AI-generated tests are selecting the wrong element.
Practical Workflow
Step 1: Upload directly to the input when possible
If the input exists in the DOM, this is usually the cleanest and most stable option.
await page.getByLabel('Upload resume').setInputFiles('tests/fixtures/resume.pdf');
await expect(page.getByText('resume.pdf')).toBeVisible();
Step 2: Handle a native chooser when the UI hides the input
Wait for the file chooser before clicking the upload button, then provide the file path programmatically.
const chooserPromise = page.waitForEvent('filechooser');
await page.getByRole('button', { name: 'Select file' }).click();
const chooser = await chooserPromise;
await chooser.setFiles(['tests/fixtures/invoice.pdf']);
Step 3: Use the CLI to verify the upload control and the resulting page state
This is a fast way to inspect whether the page uses a hidden input, a custom dialog, or a post-upload status component.
playwright-cli open https://example.com/upload
playwright-cli snapshot
playwright-cli upload ./tests/fixtures/invoice.pdf
playwright-cli snapshot
Where the Playwright CLI Skill Fits
This is exactly where Playwright CLI Browser Automation adds value. The skill gives your agent stable guidance for snapshots, uploads, downloads, tab handling, tracing, screenshots, PDFs, and fast browser investigation without forcing you to reinvent the command flow every time.
If you are building out a broader QA workflow, keep the skill installed and pair it with the wider QASkills.sh skills directory catalog so your agent can switch between browser automation, API testing, CI, accessibility, and reporting with less context loss.
Common Mistakes to Avoid
- Uploading large random files that slow CI and add no test value.
- Asserting only that the input accepted a file without checking the success message or resulting attachment row.
- Forgetting to test validation paths like wrong file type, oversized files, or duplicate uploads.
- Clicking a custom upload button without waiting for the chooser event first.
Related Reading on QASkills.sh
- Playwright CLI Complete Guide for 2026
- Playwright Trace Viewer Guide for Flaky Test Debugging
- Test Data Management Guide for Stable E2E Suites
Conclusion
Upload automation becomes reliable when you separate DOM interaction from business verification. Choose the right upload primitive, keep fixtures deterministic, and validate the outcome beyond the input element itself.