docs: use absolute paths for file uploads (#26611)

Fixes https://github.com/microsoft/playwright/issues/26536

This makes it a bit harder for MJS customers, but I guess they know that
they can do

    const dirname = path.dirname(url.fileURLToPath(import.meta.url));
This commit is contained in:
Max Schmitt 2023-08-22 17:38:23 +02:00 committed by GitHub
parent bb3152738d
commit 18e03da445
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 23 additions and 14 deletions

View File

@ -8,7 +8,7 @@
const fileChooserPromise = page.waitForEvent('filechooser');
await page.getByText('Upload file').click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles('myfile.pdf');
await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf'));
```
```java

View File

@ -1971,10 +1971,13 @@ Upload file or multiple files into `<input type=file>`.
```js
// Select one file
await page.getByLabel('Upload file').setInputFiles('myfile.pdf');
await page.getByLabel('Upload file').setInputFiles(path.join(__dirname, 'myfile.pdf'));
// Select multiple files
await page.getByLabel('Upload files').setInputFiles(['file1.txt', 'file2.txt']);
await page.getByLabel('Upload files').setInputFiles([
path.join(__dirname, 'file1.txt'),
path.join(__dirname, 'file2.txt'),
]);
// Remove all the selected files
await page.getByLabel('Upload file').setInputFiles([]);

View File

@ -339,7 +339,7 @@ respond to it via setting the input files using [`method: FileChooser.setFiles`]
```js
page.on('filechooser', async fileChooser => {
await fileChooser.setFiles('/tmp/myfile.pdf');
await fileChooser.setFiles(path.join(__dirname, '/tmp/myfile.pdf'));
});
```

View File

@ -516,10 +516,13 @@ You can select input files for upload using the [`method: Locator.setInputFiles`
```js
// Select one file
await page.getByLabel('Upload file').setInputFiles('myfile.pdf');
await page.getByLabel('Upload file').setInputFiles(path.join(__dirname, 'myfile.pdf'));
// Select multiple files
await page.getByLabel('Upload files').setInputFiles(['file1.txt', 'file2.txt']);
await page.getByLabel('Upload files').setInputFiles([
path.join(__dirname, 'file1.txt'),
path.join(__dirname, 'file2.txt'),
]);
// Remove all the selected files
await page.getByLabel('Upload file').setInputFiles([]);
@ -610,7 +613,7 @@ or use a corresponding waiting method upon your action:
const fileChooserPromise = page.waitForEvent('filechooser');
await page.getByLabel('Upload file').click();
const fileChooser = await fileChooserPromise;
await fileChooser.setFiles('myfile.pdf');
await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf'));
```
```java

View File

@ -982,7 +982,7 @@ export interface Page {
*
* ```js
* page.on('filechooser', async fileChooser => {
* await fileChooser.setFiles('/tmp/myfile.pdf');
* await fileChooser.setFiles(path.join(__dirname, '/tmp/myfile.pdf'));
* });
* ```
*
@ -1278,7 +1278,7 @@ export interface Page {
*
* ```js
* page.on('filechooser', async fileChooser => {
* await fileChooser.setFiles('/tmp/myfile.pdf');
* await fileChooser.setFiles(path.join(__dirname, '/tmp/myfile.pdf'));
* });
* ```
*
@ -1669,7 +1669,7 @@ export interface Page {
*
* ```js
* page.on('filechooser', async fileChooser => {
* await fileChooser.setFiles('/tmp/myfile.pdf');
* await fileChooser.setFiles(path.join(__dirname, '/tmp/myfile.pdf'));
* });
* ```
*
@ -4334,7 +4334,7 @@ export interface Page {
*
* ```js
* page.on('filechooser', async fileChooser => {
* await fileChooser.setFiles('/tmp/myfile.pdf');
* await fileChooser.setFiles(path.join(__dirname, '/tmp/myfile.pdf'));
* });
* ```
*
@ -12224,10 +12224,13 @@ export interface Locator {
*
* ```js
* // Select one file
* await page.getByLabel('Upload file').setInputFiles('myfile.pdf');
* await page.getByLabel('Upload file').setInputFiles(path.join(__dirname, 'myfile.pdf'));
*
* // Select multiple files
* await page.getByLabel('Upload files').setInputFiles(['file1.txt', 'file2.txt']);
* await page.getByLabel('Upload files').setInputFiles([
* path.join(__dirname, 'file1.txt'),
* path.join(__dirname, 'file2.txt'),
* ]);
*
* // Remove all the selected files
* await page.getByLabel('Upload file').setInputFiles([]);
@ -17122,7 +17125,7 @@ export interface Electron {
* const fileChooserPromise = page.waitForEvent('filechooser');
* await page.getByText('Upload file').click();
* const fileChooser = await fileChooserPromise;
* await fileChooser.setFiles('myfile.pdf');
* await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf'));
* ```
*
*/