Skip to content

Instantly share code, notes, and snippets.

@YumaInaura
Last active February 22, 2024 17:21
Show Gist options
  • Select an option

  • Save YumaInaura/b6e90b919c19ff4753ec04f20dd8838f to your computer and use it in GitHub Desktop.

Select an option

Save YumaInaura/b6e90b919c19ff4753ec04f20dd8838f to your computer and use it in GitHub Desktop.

Revisions

  1. YumaInaura revised this gist Feb 22, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PLAYWRIGHT.md
    Original 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.
    - make `Buffer` object. ( e.g use `fs` and read local file )
    - At `setFiles` specify that `Buffer` in argument.

    ```js
    import fs from 'fs'
  2. YumaInaura revised this gist Feb 22, 2024. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions PLAYWRIGHT.md
    Original file line number Diff line number Diff line change
    @@ -16,8 +16,8 @@ await fileChooser.setFiles(path.join(__dirname, 'myfile.pdf'));

    ## Resolve Example

    specify buffer as object argument of `setFiles`.

    - make buffer object. ( e.g use `fs` and read local file )
    - At `setFiles` specify that buffer in argument.

    ```js
    import fs from 'fs'
  3. YumaInaura revised this gist Feb 22, 2024. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions PLAYWRIGHT.md
    Original 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'

  4. YumaInaura revised this gist Feb 22, 2024. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion PLAYWRIGHT.md
    Original 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();
  5. YumaInaura revised this gist Feb 22, 2024. 1 changed file with 17 additions and 1 deletion.
    18 changes: 17 additions & 1 deletion PLAYWRIGHT.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,20 @@
    # Example
    # 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'
  6. YumaInaura created this gist Feb 22, 2024.
    20 changes: 20 additions & 0 deletions PLAYWRIGHT.md
    Original 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,
    })

    })
    ```