Last active
February 22, 2024 17:21
-
-
Save YumaInaura/b6e90b919c19ff4753ec04f20dd8838f to your computer and use it in GitHub Desktop.
Revisions
-
YumaInaura revised this gist
Feb 22, 2024 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,8 +16,8 @@ await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf')); ## Resolve Example - make `Buffer` object. ( e.g use `fs` and read local file ) - At `setFiles` specify that `Buffer` in argument. ```js import fs from 'fs' -
YumaInaura revised this gist
Feb 22, 2024 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,8 +16,8 @@ await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf')); ## Resolve Example - make buffer object. ( e.g use `fs` and read local file ) - At `setFiles` specify that buffer in argument. ```js import fs from 'fs' -
YumaInaura revised this gist
Feb 22, 2024 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -16,6 +16,9 @@ await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf')); ## Resolve Example specify buffer as object argument of `setFiles`. ```js import fs from 'fs' -
YumaInaura revised this gist
Feb 22, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ This formal example select file but does not send Form data. https://playwright.dev/docs/api/class-filechooser ```js // Start waiting for file chooser before clicking. Note no await. const fileChooserPromise = page.waitForEvent('filechooser'); await page.getByText('Upload file').click(); -
YumaInaura revised this gist
Feb 22, 2024 . 1 changed file with 17 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,20 @@ # Playwright – select file and send formData ## Trouble This formal example select file but does not send Form data. https://playwright.dev/docs/api/class-filechooser ``` // Start waiting for file chooser before clicking. Note no await. const fileChooserPromise = page.waitForEvent('filechooser'); await page.getByText('Upload file').click(); const fileChooser = await fileChooserPromise; await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf')); ``` ## Resolve Example ```js import fs from 'fs' -
YumaInaura created this gist
Feb 22, 2024 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ # Example ```js import fs from 'fs' test('UPLOAD SAMPLE', async ({ page }) => { const fileBuffer = fs.readFileSync('/path/to/example.csv') await page.getByText('Upload file').click() const fileChooserPromise = page.waitForEvent('filechooser') const fileChooser = await fileChooserPromise await fileChooser.setFiles({ name: 'filename', mimeType: 'xxx', buffer: fileBuffer, }) }) ```