From c4c79733d7bc4702c02fdcd8e16793dc0e78a91c Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 1 Jul 2026 08:50:57 -0500 Subject: [PATCH 1/4] Allow attaching multiple files to an input --- src/Api/Concerns/InteractsWithElements.php | 2 +- src/Playwright/Locator.php | 4 +-- tests/Browser/Webpage/AttachTest.php | 30 ++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/Api/Concerns/InteractsWithElements.php b/src/Api/Concerns/InteractsWithElements.php index 24566e7e..2e563b7d 100644 --- a/src/Api/Concerns/InteractsWithElements.php +++ b/src/Api/Concerns/InteractsWithElements.php @@ -178,7 +178,7 @@ public function uncheck(string $field, ?string $value = null): self /** * Attach the given file to the field. */ - public function attach(string $field, string $path): self + public function attach(string $field, string|array $path): self { $this->guessLocator($field)->setInputFiles($path); diff --git a/src/Playwright/Locator.php b/src/Playwright/Locator.php index b628b61a..307266aa 100644 --- a/src/Playwright/Locator.php +++ b/src/Playwright/Locator.php @@ -652,9 +652,9 @@ public function tap(?array $options = null): void /** * Set input files for a file input element. */ - public function setInputFiles(string $path): void + public function setInputFiles(string|array $path): void { - $params = ['localPaths' => [$path]]; + $params = ['localPaths' => is_array($path) ? $path : [$path]]; $response = $this->sendMessage('setInputFiles', $params); $this->processVoidResponse($response); diff --git a/tests/Browser/Webpage/AttachTest.php b/tests/Browser/Webpage/AttachTest.php index 580a20e5..bb65582c 100644 --- a/tests/Browser/Webpage/AttachTest.php +++ b/tests/Browser/Webpage/AttachTest.php @@ -47,3 +47,33 @@ // Clean up unlink($tempFile); }); + +it('may attach multiple files to a file input', function (): void { + Route::get('/', fn (): string => ' +
+ +
+ '); + + $page = visit('/'); + + // Create temporary files + $tempFiles = [ + tempnam(sys_get_temp_dir(), 'test'), + tempnam(sys_get_temp_dir(), 'test'), + ]; + file_put_contents($tempFiles[0], 'test content 1'); + file_put_contents($tempFiles[1], 'test content 2'); + + $page->attach('avatar', $tempFiles); + + // Check that the files are attached + $fileNames = array_map(fn ($file) => basename($file), $tempFiles); + expect($page->script('() => document.querySelector("input[name=avatar]").files.length'))->toBe(count($tempFiles)); + expect($page->script('() => document.querySelector("input[name=avatar]").files.map(file => file.name)'))->toBe($fileNames); + + // Clean up + foreach ($tempFiles as $tempFile) { + unlink($tempFile); + } +}); From e845e9537c00d9d36e598b526f48338728390849 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 1 Jul 2026 08:54:21 -0500 Subject: [PATCH 2/4] update to plural --- src/Api/Concerns/InteractsWithElements.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/Concerns/InteractsWithElements.php b/src/Api/Concerns/InteractsWithElements.php index 2e563b7d..1e1081d9 100644 --- a/src/Api/Concerns/InteractsWithElements.php +++ b/src/Api/Concerns/InteractsWithElements.php @@ -176,7 +176,7 @@ public function uncheck(string $field, ?string $value = null): self } /** - * Attach the given file to the field. + * Attach the given files to the field. */ public function attach(string $field, string|array $path): self { From c4c4c83b1aac925bd075a560eae8b53de7b688f9 Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 1 Jul 2026 12:50:14 -0500 Subject: [PATCH 3/4] Add type --- src/Playwright/Locator.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Playwright/Locator.php b/src/Playwright/Locator.php index 307266aa..2279335d 100644 --- a/src/Playwright/Locator.php +++ b/src/Playwright/Locator.php @@ -651,6 +651,8 @@ public function tap(?array $options = null): void /** * Set input files for a file input element. + * + * @param string|array $path */ public function setInputFiles(string|array $path): void { From 119868114db36b799d3b62862bb21cb817b6a5cf Mon Sep 17 00:00:00 2001 From: Jordan Welch Date: Wed, 1 Jul 2026 12:52:41 -0500 Subject: [PATCH 4/4] Add type to `attach` as well --- src/Api/Concerns/InteractsWithElements.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Api/Concerns/InteractsWithElements.php b/src/Api/Concerns/InteractsWithElements.php index 1e1081d9..1d444ff3 100644 --- a/src/Api/Concerns/InteractsWithElements.php +++ b/src/Api/Concerns/InteractsWithElements.php @@ -177,6 +177,8 @@ public function uncheck(string $field, ?string $value = null): self /** * Attach the given files to the field. + * + * @param string|array $path */ public function attach(string $field, string|array $path): self {