Skip to content

Commit

Permalink
Update the browser#1097 release notes
Browse files Browse the repository at this point in the history
The API has changed so that it requires working with the experimental
fs module to upload files from the local file system.
  • Loading branch information
ankur22 committed Mar 18, 2024
1 parent e32e5d2 commit 59b4c59
Showing 1 changed file with 3 additions and 36 deletions.
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

0 comments on commit 59b4c59

Please sign in to comment.