-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): update main readme to point to examples + add a file …
…uploads example
- Loading branch information
1 parent
9826fd6
commit baffb8d
Showing
3 changed files
with
49 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
const { firefox } = require("playwright"); | ||
|
||
/** | ||
* In this script, we will upload a file to a web page. | ||
* | ||
* Steps summary | ||
* 1. Open the sample file upload at https://cgi-lib.berkeley.edu/ex/fup.html | ||
* 2. Automate file upload with setInputFiles | ||
*/ | ||
|
||
(async () => { | ||
// Launch a headless browser instance of chromium, webkit or firefox | ||
const browser = await firefox.launch(); | ||
|
||
// Use the default browser context to create a new tab and navigate to URL | ||
const page = await browser.newPage(); | ||
await page.goto('https://cgi-lib.berkeley.edu/ex/fup.html'); | ||
|
||
// Get an element handle to the file upload input | ||
const handle = await page.$('input[type="file"]'); | ||
|
||
// Use the setInputFiles API to upload this file. File paths are relative to | ||
// the current working directory. It is also possible to upload multiple files | ||
// or use base64 encoded data, instead of a file. See API docs. | ||
// https://github.com/microsoft/playwright/blob/master/docs/api.md#elementhandlesetinputfilesfiles | ||
await handle.setInputFiles('upload.js'); | ||
|
||
// Click on the form submit element | ||
await page.click('input[type="submit"]'); | ||
|
||
// Take a screenshot of the uploaded state and close the browser | ||
await page.screenshot({ path: 'uploaded.png' }); | ||
await browser.close(); | ||
})(); |