Here’s the code sample from our tutorial on how to upload files in Playwright

 

const { test, expect } = require('@playwright/test');
test.describe('File Picker', () => {
test.beforeEach(async ({ page }) => {
await page.goto('https://kitchen.applitools.com/ingredients/file-picker');
});
test('should upload a photo to the file picker', async ({ page }) => {
await page.setInputFiles('#photo-upload', './fixtures/images/french-toast.jpg');
const $photoUpload = await page.$('#photo-upload');
const $photoUploadParent = await $photoUpload.$('xpath=..');
const $photoUploadFigure = await $photoUploadParent.$$('figure');
expect($photoUploadFigure).toHaveLength(1);
});
});
view raw file-picker.spec.js delivered with ❤ by emgithub

View on GitHub
Colby Fayock
Developer Advocate

Ready for the next generation of testing?

Get started today Schedule a demo