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

Update browser#1097 release notes #3650

Merged
merged 1 commit into from
Mar 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 3 additions & 36 deletions release notes/v0.50.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ k6 `v0.50.0` is here 🎉! This release includes:

## New features

### Add support for uploading files from the browser module [browser#1097](https://github.com/grafana/xk6-browser/pull/1097)
### Add support for uploading files from the browser module [browser#1097](https://github.com/grafana/xk6-browser/pull/1097), [browser#1244](https://github.com/grafana/xk6-browser/pull/1244)

You can now upload files using the available input forms on the website under test. The new API is `setInputFiles` which can be called from a `page`, `frame` or `elementHandle` types. It can upload one or more files from the local filesystem, or one or more files encoded in the test script, or a combination of both files from the filesystem and from within the test script.
You can now upload files using the available input forms on the website under test. The new API is `setInputFiles` which can be called from a `page`, `frame` or `elementHandle` types. It can upload one or more files encoded in the test script. To upload files from the local file system, work with the [experimental fs module](https://grafana.com/docs/k6/latest/javascript-api/k6-experimental/fs/).

<details>
<summary>Expand to see the examples.</summary>
Expand All @@ -35,26 +35,7 @@ For the following examples, we will use the HTML file:
</html>
```

Uploading a file from the local filesystem can be achieved with the following script:

```js
export default async function () {
const page = browser.newPage();

await page.goto(url)

// Set the path relative to the current working directory.
page.setInputFiles('input[id="upload"]', 'test.txt')

// Click on the submit button on the form to upload the file.
const submitButton = page.locator('input[type="submit"]')
await Promise.all([page.waitForNavigation(), submitButton.click()])

page.close();
}
```

Uploading a file that is encoded in the test script can be achieved with the following script:
Uploading a file can be achieved with the following script:

```js
// Import the k6 encoder module.
Expand All @@ -78,26 +59,12 @@ export default async function () {

Uploading multiple files can be done with the use of an array:

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

or

```js
page.setInputFiles('input[id="upload"]',
[{ name: 'test.txt', mimetype: 'text/plain', buffer: encoding.b64encode('Hello World') },
{ name: 'test.json', mimetype: 'text/json', buffer: encoding.b64encode('{"message": "Hello World"}') }])
```

And can be a combination of both:

```js
page.setInputFiles('input[id="upload"]',
['test.txt',
{ name: 'test.json', mimetype: 'text/json', buffer: encoding.b64encode('{"message": "Hello World"}') }])
```

</details>

Thanks to @bandorko! :bow: :tada:
Expand Down
Loading