Skip to content

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.

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

Max Schmitt18e03da44543
diff --git a/docs/src/api/class-filechooser.md b/docs/src/api/class-filechooser.md
index cf6407cb55..0edb5b9cf4 100644
--- a/docs/src/api/class-filechooser.md
+++ b/docs/src/api/class-filechooser.md
@@ -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
diff --git a/docs/src/api/class-locator.md b/docs/src/api/class-locator.md
index 7948644be0..c370ecdaaf 100644
--- a/docs/src/api/class-locator.md
+++ b/docs/src/api/class-locator.md
@@ -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([]);
diff --git a/docs/src/api/class-page.md b/docs/src/api/class-page.md
index df9f15459c..ee81788916 100644
--- a/docs/src/api/class-page.md
+++ b/docs/src/api/class-page.md
@@ -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'));
});
```
diff --git a/docs/src/input.md b/docs/src/input.md
index 97dbc6718b..43d1e09226 100644
--- a/docs/src/input.md
+++ b/docs/src/input.md
@@ -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
diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts
index aea8dca052..67d5e562d3 100644
--- a/packages/playwright-core/types/types.d.ts
+++ b/packages/playwright-core/types/types.d.ts
@@ -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'));
* ```
*
*/