From 131c3c62088e9c8cb3dd6aa54dd21c99da1f8e75 Mon Sep 17 00:00:00 2001 From: ankur22 Date: Mon, 18 Mar 2024 11:22:38 +0000 Subject: [PATCH] Update the browser#1097 release notes The API has changed so that it requires working with the experimental fs module to upload files from the local file system. --- release notes/v0.50.0.md | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) diff --git a/release notes/v0.50.0.md b/release notes/v0.50.0.md index 01abe3b1554..e51733a9b80 100644 --- a/release notes/v0.50.0.md +++ b/release notes/v0.50.0.md @@ -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/).
Expand to see the examples. @@ -35,26 +35,7 @@ For the following examples, we will use the HTML file: ``` -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. @@ -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"}') }]) -``` -
Thanks to @bandorko! :bow: :tada: