release notes/v0.57.0.md
k6 v0.57.0 is here 🎉! This release includes:
k6 new command now supports templates and ProjectIDs.k6/experimental/csv module gets a new asObjects option.k6/experimental/browser module, in favor of k6/browser.internal package.k6/experimental/browser. If you're still using it, follow the instructions to move to the graduated and stable k6/browser module.internal package. This was based on the publicly available extensions for k6 and may break private ones. More APIs will likely be removed or updated in follow-up releases after this more mechanical change..ts extension. It also deprecates experimental_enhanced compatibility mode as it is no longer necessary.The k6 team has been developing a new official jslib dedicated to functional testing. While it is still under active development and will potentially see breaking changes, the set of APIs and behaviors it offers are meant to make their way into k6 eventually, and it is now available for early feedback.
k6-testing is a k6 JavaScript library that offers a seamless way to write functional tests in k6, using a Playwright-compatible assertions API. It exposes an expect function, with which assertions can be performed using specific matchers that reflect the expected results.
Unlike current k6's check when expects assertions fail, the test will immediately fail with a clear error message, including the expected and actual values in a similar fashion to what users would observe when using Playwright assertions.
There are many generic matchers (and more to come), such as toEqual, toBe, or toBeTruthy, to only name a few, that can be used to assert conditions during a k6 test.
import { expect } from 'https://jslib.k6.io/k6-testing/0.2.0/index.js';
export default function () {
const response = http.get('https://test.k6.io');
expect(response.status).toEqual(200);
expect(response.body).toBeTruthy();
expect(response.json()).toEqual(JSON.stringify({ message: 'Hello, world!' }));
}
k6-jslib-testing also includes browser-specific async matchers that wait until the expected condition is met such as toBeVisible, toBeDisabled, or toBeChecked, to name a few.
import { expect } from "https://jslib.k6.io/k6-testing/0.2.0/index.js";
import { browser } from "k6/browser";
export const options = {
scenarios: {
ui: {
executor: "shared-iterations",
options: {
browser: {
type: "chromium",
},
},
},
},
};
export default async function () {
const page = await browser.newPage();
try {
// Navigate to the page
await page.goto("https://test.k6.io/my_messages.php");
// Type into the login input field: 'testlogin'
const loc = await page.locator('input[name="login"]');
await loc.type("testlogin");
// Assert that the login input field is visible
await expect(page.locator('input[name="login"]')).toBeVisible();
// Expecting this to fail as we have typed 'testlogin' into the input instead of 'foo'
await expect(page.locator('input[name="login"]')).toHaveValue("foo");
} finally {
await page.close();
}
}
It is currently available as part of the jslib.k6.io repository and is available to use in your k6 tests by adding the following import:
import { expect } from "https://jslib.k6.io/k6-testing/0.2.0/index.js";
Try it out and give us feedback or contribute to the project on the k6-jslib-testing repository!
--template and --project-id flags for k6 new command #4153The k6 new command has been revamped to provide an improved experience when scaffolding new k6 tests. It now supports a --template flag with options such as minimal, protocol, and browser, letting you generate a script tailored to your specific use case.
The command also now accepts a --project-id flag, which allows you to easily parameterize the test's Grafana Cloud configuration.
# Create a new k6 script using the 'protocol' template
$ k6 new --template protocol
# Create a Grafana k6 cloud-ready script with a specific project ID
$ k6 new --project-id 12345
asObjects option in k6/experimental/csv module #4295The CSV module's parsing operations now support the asObjects option, which enables parsing CSV data into JavaScript objects instead of arrays of strings (the default behavior).
When asObjects is set to true, the module parses CSV data into objects where:
With the option set to true,
import http from 'k6/http';
import csv from 'k6/experimental/csv';
const csvData = csv.parse('data.csv', { asObjects: true });
the following CSV file:
name,age,city
John,30,New York
Jane,25,Los Angeles
will be parsed into the following JavaScript objects:
[
{ name: 'John', age: '30', city: 'New York' },
{ name: 'Jane', age: '25', city: 'Los Angeles' },
]
Refer to the CSV module's documentation for more information.
xk6-browser-data- to k6browser-data-.file scheme URLs across file loading APIs - open, k6/experimental/fs.open and k6/net/grpc.Client#load.--local-execution runs by isolating Archive's urls.modulestest to make experimental streams test simpler.browser module working with reused VUs that originally weren't used in browser scenarios.