API …
Playwright lab

Dialogs, downloads, uploads

JS dialogs, beforeunload, real downloads and every flavour of file upload, including file choosers.

Practice tasks

  • Register page.once('dialog') before clicking: accept the confirm, dismiss it, then answer the prompt with text.
  • Assert dialog.type(), dialog.message() and dialog.defaultValue() for alert, confirm and prompt.
  • Enable the leave warning and handle the beforeunload dialog when you navigate away (page.close({ runBeforeUnload: true })).
  • Wait for page.waitForEvent('download') on the CSV link; assert suggestedFilename() and read the file with download.path().
  • Download the generated report and parse its content.
  • Upload one file, several files, a Buffer payload (name, mimeType, buffer) and clear the selection with setInputFiles([]).
  • Use page.waitForEvent('filechooser') with the custom “Choose files” button.
  • Send the files to the API and assert the response lists names and sizes.

More Playwright lab practice