公式ドキュメント
実装例
ローカルのレポジトリに含まれているファイルをアップロードする
fileupload.ts
import { chromium } from 'playwright'
describe('upload file', () => {
const filePathA = '../videos/a.webm':
const filePathB = '../videos/b.webm';
test('upload file', async () => {
const browser = await chromium.lanch()
const context = await browser.newContext()
const page = await context.newPage()
await page.goto(url)
//複数投稿可能であればArrayにしてテスト可能
//setInputFilesを使う
await page.setInputFiles('input[name="file"]', [filepathA, filepathB])
}
こんなやり方も
import { chromium } from 'playwright'
describe('upload file', () => {
const filePathA = '../videos/a.webm':
const filePathB = '../videos/b.webm';
test('upload file', async () => {
const browser = await chromium.lanch()
const context = await browser.newContext()
const page = await context.newPage()
await page.goto(url)
//filechooserを使う
page.on('filechooser', async (filechooser) => {
await filechooser.setFiles([filePathA, filePathB])
}
await page.click("#fileUpload", {force: true})
参考youtube