Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SetInputFiles support #384

Closed
5 of 6 tasks
inancgumus opened this issue Jun 9, 2022 · 2 comments · Fixed by #1097
Closed
5 of 6 tasks

Add SetInputFiles support #384

inancgumus opened this issue Jun 9, 2022 · 2 comments · Fixed by #1097
Labels
feature A new feature playwright Issue relating to Playwright compatibility user request Requested by the community

Comments

@inancgumus
Copy link
Member

inancgumus commented Jun 9, 2022

Inspired by #355, and for further PW compatibility, we might want to add SetInputFiles support to Page and Frame.

@inancgumus inancgumus added the feature A new feature label Jun 9, 2022
@inancgumus inancgumus added the playwright Issue relating to Playwright compatibility label Jun 10, 2022
@justmeben
Copy link

would be much appreciated

@ankur22
Copy link
Collaborator

ankur22 commented Mar 14, 2024

We have had to scale back how this feature works in k6 as compared to Playwright. In Playwright you have the ability to read from the local filesystem by providing the file path in the API call:

await page.setInputFiles('input[id="upload"]', 'test.txt')

This isn't possible in the browser module for k6 since it's not safe when k6 is deployed in a remote server. This would give the browser module access to the local FS of the server. Instead you can work with the experimental fs module to provide the same functionality, albeit with a bit more boiler plate code:

...
let file;
(async function () {
  file = await open('/abs/path/to/file.txt');
})();

...

export default async function () {
...
  const buffer = await readAll(file);
  page.setInputFiles('input[id="upload"]', { name: 'file.txt', mimetype: 'text/plain', buffer: encoding.b64encode(buffer) })
...
}

async function readAll(file) {
...
}

You can find more details and a working test script in #1244.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature playwright Issue relating to Playwright compatibility user request Requested by the community
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants