<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>jslib on Grafana Labs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/</link><description>Recent content in jslib on Grafana Labs</description><generator>Hugo -- gohugo.io</generator><language>en</language><atom:link href="/docs/k6/v2.3.x/javascript-api/jslib/index.xml" rel="self" type="application/rss+xml"/><item><title>aws</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/aws/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/aws/</guid><content><![CDATA[&lt;h1 id=&#34;aws&#34;&gt;aws&lt;/h1&gt;
&lt;!-- TODO: Add content --&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The source code for this library can be found in the &lt;a href=&#34;https://github.com/grafana/k6-jslib-aws&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;grafana/k6-jslib-aws&lt;/a&gt; GitHub repository.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;aws&lt;/code&gt; module is an external JavaScript library that helps interact with a subset of AWS services in the context of k6 test scripts.&lt;/p&gt;
&lt;ul&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/awsconfig/&#34;&gt;AWSConfig&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/eventbridgeclient/&#34;&gt;EventBridgeClient&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/kinesisclient/&#34;&gt;KinesisClient&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/kmsclient/&#34;&gt;KMSClient&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/lambdaclient/&#34;&gt;LambdaClient&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/s3client/&#34;&gt;S3Client&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/secretsmanagerclient/&#34;&gt;SecretsManagerClient&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/signaturev4/&#34;&gt;SignatureV4&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/sqsclient/&#34;&gt;SQSClient&lt;/a&gt;&lt;/li&gt;&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/aws/systemsmanagerclient/&#34;&gt;SystemsManagerClient&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;
]]></content><description>&lt;h1 id="aws">aws&lt;/h1>
&lt;!-- TODO: Add content -->
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The source code for this library can be found in the &lt;a href="https://github.com/grafana/k6-jslib-aws" target="_blank" rel="noopener noreferrer">grafana/k6-jslib-aws&lt;/a> GitHub repository.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>The &lt;code>aws&lt;/code> module is an external JavaScript library that helps interact with a subset of AWS services in the context of k6 test scripts.&lt;/p></description></item><item><title>httpx</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/httpx/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/httpx/</guid><content><![CDATA[&lt;h1 id=&#34;httpx&#34;&gt;httpx&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The source code for this library can be found in the &lt;a href=&#34;https://github.com/k6io/k6-jslib-httpx&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;grafana/k6-jslib-httpx&lt;/a&gt; GitHub repository.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;httpx&lt;/code&gt; module is an external JavaScript library that wraps around the native 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6-http/&#34;&gt;k6/http&lt;/a&gt; module.
It&amp;rsquo;s an HTTP client with features that are not yet available in the native module.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Ability to set HTTP options globally (such as timeout).&lt;/li&gt;
&lt;li&gt;Ability to set default tags and headers that will be used for all requests.&lt;/li&gt;
&lt;li&gt;More user-friendly arguments to request functions (get, post, put take the same arguments).&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;code&gt;httpx&lt;/code&gt; module integrates well with the expect library.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-caution&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Caution&lt;/p&gt;&lt;p&gt;This library is in active development. It&amp;rsquo;s stable enough to be useful, but you can watch the &lt;a href=&#34;https://github.com/k6io/k6-jslib-httpx&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;GitHub repository&lt;/a&gt; to be notified when a new version is released.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h3 id=&#34;methods&#34;&gt;Methods&lt;/h3&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/asyncrequest/&#34;&gt;asyncRequest(method, url, [body], [params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Generic method for making arbitrary, asynchronous HTTP requests.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/request/&#34;&gt;request(method, url, [body], [params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Generic method for making arbitrary HTTP requests.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/get/&#34;&gt;get(url, [body], [params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Makes GET request&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/post/&#34;&gt;post(url, [body], [params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Makes POST request&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/put/&#34;&gt;put(url, [body], [params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Makes PUT request&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/patch/&#34;&gt;patch(url, [body], [params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Makes PATCH request&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/delete/&#34;&gt;delete(url, [body], [params])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Makes DELETE request&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/batch/&#34;&gt;batch(requests)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Batches multiple HTTP requests together to issue them in parallel.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/setbaseurl/&#34;&gt;setBaseUrl(url)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Sets the base URL for the session&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/addheader/&#34;&gt;addHeader(key, value)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Adds a header to the session&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/addheaders/&#34;&gt;addHeaders(object)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Adds multiple headers to the session&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/clearheader/&#34;&gt;clearHeader(name)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Removes header from the session&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/addtag/&#34;&gt;addTag(key, value)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Adds a tag to the session&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/addtags/&#34;&gt;addTags(object)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Adds multiple tags to the session&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/httpx/cleartag/&#34;&gt;clearTag(name)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Removes tag from the session&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h3 id=&#34;example&#34;&gt;Example&lt;/h3&gt;
&lt;!-- md-k6:fixedscenarios --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { fail } from &amp;#39;k6&amp;#39;;
import { Httpx } from &amp;#39;https://jslib.k6.io/httpx/0.1.0/index.js&amp;#39;;
import { randomIntBetween } from &amp;#39;https://jslib.k6.io/k6-utils/1.2.0/index.js&amp;#39;;

export const options = {
  vus: 1,
  iterations: 1,
};

const USERNAME = `user${randomIntBetween(1, 100000)}@example.com`; // random email address
const PASSWORD = &amp;#39;secretpassword&amp;#39;;

const session = new Httpx({
  baseURL: &amp;#39;https://quickpizza.grafana.com&amp;#39;,
  headers: {
    &amp;#39;User-Agent&amp;#39;: &amp;#39;My custom user agent&amp;#39;,
  },
  timeout: 20000, // 20s timeout.
});

export default function testSuite() {
  const registrationResp = session.post(
    `/api/users`,
    JSON.stringify({
      username: USERNAME,
      password: PASSWORD,
    })
  );

  if (registrationResp.status !== 201) {
    fail(&amp;#39;registration failed&amp;#39;);
  }

  const loginResp = session.post(
    `/api/users/token/login`,
    JSON.stringify({
      username: USERNAME,
      password: PASSWORD,
    })
  );

  if (loginResp.status !== 200) {
    fail(&amp;#39;Authentication failed&amp;#39;);
  }

  const authToken = loginResp.json(&amp;#39;token&amp;#39;);

  // set the authorization header on the session for the subsequent requests.
  session.addHeader(&amp;#39;Authorization&amp;#39;, `Bearer ${authToken}`);

  const payload = {
    stars: 5,
    pizza_id: 1,
  };

  // this request uses the Authorization header set above.
  const respCreateRating = session.post(`/api/ratings`, JSON.stringify(payload));

  if (respCreateRating.status !== 201) {
    fail(&amp;#39;Rating creation failed&amp;#39;);
  } else {
    console.log(&amp;#39;New rating created&amp;#39;);
  }
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="httpx">httpx&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The source code for this library can be found in the &lt;a href="https://github.com/k6io/k6-jslib-httpx" target="_blank" rel="noopener noreferrer">grafana/k6-jslib-httpx&lt;/a> GitHub repository.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>The &lt;code>httpx&lt;/code> module is an external JavaScript library that wraps around the native
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6-http/">k6/http&lt;/a> module.
It&amp;rsquo;s an HTTP client with features that are not yet available in the native module.&lt;/p></description></item><item><title>k6chaijs</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/</guid><content><![CDATA[&lt;h1 id=&#34;k6chaijs&#34;&gt;k6chaijs&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The source code for this library can be found in the &lt;a href=&#34;https://github.com/grafana/k6-jslib-k6chaijs&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;grafana/k6-jslib-k6chaijs&lt;/a&gt; GitHub repository.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;k6chaijs&lt;/code&gt; is a library to provide BDD assertions in k6 based on &lt;a href=&#34;https://www.chaijs.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;ChaiJS&lt;/a&gt;. You can use &lt;code&gt;k6chaijs&lt;/code&gt; as an alternative to 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/&#34;&gt;check&lt;/a&gt; and 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/group/&#34;&gt;group&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;With this library, you get the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;BDD style of assertions for more expressive language&lt;/li&gt;
&lt;li&gt;Chainable assertions&lt;/li&gt;
&lt;li&gt;More powerful assertions functions such as: &lt;code&gt;deep&lt;/code&gt;, &lt;code&gt;nested&lt;/code&gt;, &lt;code&gt;ordered&lt;/code&gt;, etc.&lt;/li&gt;
&lt;li&gt;Automatic assertion messages&lt;/li&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/error-handling/&#34;&gt;Exception handling&lt;/a&gt; for better test stability&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;installation&#34;&gt;Installation&lt;/h2&gt;
&lt;p&gt;This library is hosted on &lt;a href=&#34;https://jslib.k6.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;jslib&lt;/a&gt; and can be imported directly in your k6 script.&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.5.0.1/index.js&amp;#39;;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively, you can use a copy of this file stored locally. The source code is available on &lt;a href=&#34;https://github.com/grafana/k6-jslib-k6chaijs&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;The following example tests a hypothetical HTTP API that returns a JSON array of objects. Copy the following code, and save it as &lt;code&gt;script.js&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import http from &amp;#39;k6/http&amp;#39;;
import { describe, expect } from &amp;#39;https://jslib.k6.io/k6chaijs/4.3.4.3/index.js&amp;#39;;

export default function testSuite() {
  describe(&amp;#39;Fetch a list of pizza names&amp;#39;, () =&amp;gt; {
    const response = http.get(&amp;#39;https://quickpizza.grafana.com/api/names&amp;#39;);

    expect(response.status, &amp;#39;response status&amp;#39;).to.equal(200);
    expect(response).to.have.validJsonBody();
    expect(response.json(&amp;#39;names&amp;#39;).length, &amp;#39;number of names&amp;#39;).to.be.above(1);
  });
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;When you run this test with &lt;code&gt;k6 run script.js&lt;/code&gt;, the output at the end of the test shows:&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;Bash&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-bash&#34;&gt;█ Fetch a list of public crocodiles
  ✓ expected response status to equal 200
  ✓ has valid json body
  ✓ expected number of crocs to be above 4&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If you are familiar with k6, the result is the same as using 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/&#34;&gt;check&lt;/a&gt; and 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/group/&#34;&gt;group&lt;/a&gt;. Note that 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/expect/&#34;&gt;expect&lt;/a&gt; might add or extend the assertion message.&lt;/p&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;API&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/config/&#34;&gt;config&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Options to change &lt;code&gt;k6chaijs&lt;/code&gt; behaviour.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/describe/&#34;&gt;describe&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A wrapper of 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/group/&#34;&gt;group&lt;/a&gt; that catches exceptions to allow continuing the test execution. It returns a boolean to indicate the success of all its &lt;code&gt;k6chaijs&lt;/code&gt; assertions.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/k6chaijs/expect/&#34;&gt;expect&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;A wrapper of 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/&#34;&gt;check&lt;/a&gt; that provides BDD style of assertions.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;plugins&#34;&gt;Plugins&lt;/h2&gt;
&lt;p&gt;It&amp;rsquo;s possible to extend the default functionality with &lt;a href=&#34;https://www.chaijs.com/plugins/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Chai plugins&lt;/a&gt;. To use a plugin or build a Chai version with plugins, follow the instructions in this &lt;a href=&#34;https://community.grafana.com/t/how-to-build-plugins-for-chaijs/97010/3&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;example&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;read-more&#34;&gt;Read more&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/testing-guides/use-chai-with-k6/&#34;&gt;Use chai with k6&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
]]></content><description>&lt;h1 id="k6chaijs">k6chaijs&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The source code for this library can be found in the &lt;a href="https://github.com/grafana/k6-jslib-k6chaijs" target="_blank" rel="noopener noreferrer">grafana/k6-jslib-k6chaijs&lt;/a> GitHub repository.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>&lt;code>k6chaijs&lt;/code> is a library to provide BDD assertions in k6 based on &lt;a href="https://www.chaijs.com/" target="_blank" rel="noopener noreferrer">ChaiJS&lt;/a>. You can use &lt;code>k6chaijs&lt;/code> as an alternative to
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/check/">check&lt;/a> and
&lt;a href="/docs/k6/v2.3.x/javascript-api/k6/group/">group&lt;/a>.&lt;/p></description></item><item><title>HTTP instrumentation for Pyroscope</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/</guid><content><![CDATA[&lt;h1 id=&#34;http-instrumentation-for-pyroscope&#34;&gt;HTTP instrumentation for Pyroscope&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The source code for this library can be found in the &lt;a href=&#34;https://github.com/grafana/jslib.k6.io/tree/main/lib/http-instrumentation-pyroscope&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;grafana/jslib.k6.io&lt;/a&gt; GitHub repository.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;http-instrumentation-pyroscope&lt;/code&gt; module allows you to &lt;em&gt;instrument&lt;/em&gt; HTTP requests in a way that lets you tag Grafana Cloud Profiles with relevant information generated from k6 tests.&lt;/p&gt;
&lt;h2 id=&#34;about-baggage-header&#34;&gt;About baggage header&lt;/h2&gt;
&lt;p&gt;The &lt;em&gt;baggage header&lt;/em&gt; is a standardized HTTP header used to propagate distributed context. The &lt;a href=&#34;https://www.w3.org/TR/baggage/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;W3C specification&lt;/a&gt; goes into more detail on the specifics, but like many other headers, the baggage header is a list of key-value pairs.&lt;/p&gt;
&lt;p&gt;This module, by default, adds three key-value pairs:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Scenario name&lt;/li&gt;
&lt;li&gt;Name of the request (URL if not set)&lt;/li&gt;
&lt;li&gt;Value of &lt;code&gt;__ENV.K6_CLOUDRUN_TEST_RUN_ID&lt;/code&gt;, which is set automatically in Grafana Cloud k6.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Class/Function&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/instrumenthttp/&#34;&gt;instrumentHTTP&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Instruments the k6 http module with baggage header.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-pyroscope/client/&#34;&gt;Client&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Configurable Client that exposes instrumented HTTP operations.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;This example demonstrates how to use the this library to instrument every HTTP request made in a script with the &lt;code&gt;baggage&lt;/code&gt; header.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { check } from &amp;#39;k6&amp;#39;;
import pyroscope from &amp;#39;https://jslib.k6.io/http-instrumentation-pyroscope/1.0.2/index.js&amp;#39;;
import http from &amp;#39;k6/http&amp;#39;;

// instrumentHTTP will ensure that all requests made by the http module
// from this point forward will have a baggage context attached.
pyroscope.instrumentHTTP();

export default () =&amp;gt; {
  // the instrumentHTTP call in the init context replaced
  // the http module with a version that will automatically
  // attach a baggage header to every request.
  const res = http.get(&amp;#39;http://httpbin.org/get&amp;#39;, {
    headers: {
      &amp;#39;X-Example-Header&amp;#39;: &amp;#39;instrumented/get&amp;#39;,
    },
  });
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="http-instrumentation-for-pyroscope">HTTP instrumentation for Pyroscope&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The source code for this library can be found in the &lt;a href="https://github.com/grafana/jslib.k6.io/tree/main/lib/http-instrumentation-pyroscope" target="_blank" rel="noopener noreferrer">grafana/jslib.k6.io&lt;/a> GitHub repository.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>The &lt;code>http-instrumentation-pyroscope&lt;/code> module allows you to &lt;em>instrument&lt;/em> HTTP requests in a way that lets you tag Grafana Cloud Profiles with relevant information generated from k6 tests.&lt;/p></description></item><item><title>HTTP instrumentation for Tempo</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-tempo/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-tempo/</guid><content><![CDATA[&lt;h1 id=&#34;http-instrumentation-for-tempo&#34;&gt;HTTP instrumentation for Tempo&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The source code for this library can be found in the &lt;a href=&#34;https://github.com/grafana/jslib.k6.io/tree/main/lib/http-instrumentation-tempo&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;grafana/jslib.k6.io&lt;/a&gt; GitHub repository.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;http-instrumentation-tempo&lt;/code&gt; module allows you to &lt;em&gt;instrument&lt;/em&gt; HTTP requests so that they emit traces as the test runs. Use it to include a tracing context in HTTP requests, which can then be used by a tracing backend such as &lt;a href=&#34;/docs/grafana-cloud/testing/k6/analyze-results/integration-with-grafana-cloud-traces/&#34;&gt;Grafana Tempo&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;migration-from-k6experimentaltracing&#34;&gt;Migration from &lt;code&gt;k6/experimental/tracing&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;This jslib is a drop in replacement, so all you need to migrate to it is to replace &lt;code&gt;&#39;k6/experimental/tracing&#39;&lt;/code&gt; import with &lt;code&gt;&#39;https://jslib.k6.io/http-instrumentation-tempo/1.0.1/index.js&#39;&lt;/code&gt;&lt;/p&gt;
&lt;h2 id=&#34;about-trace-contexts&#34;&gt;About trace contexts&lt;/h2&gt;
&lt;p&gt;A &lt;em&gt;trace context&lt;/em&gt; is a set of standardized HTTP headers added to a request that lets a tracing system correlate it with other requests as they navigate through a system. The trace context specifications, such as the supported &lt;a href=&#34;https://www.w3.org/TR/trace-context/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;W3C Trace Context&lt;/a&gt; and &lt;a href=&#34;https://www.jaegertracing.io/docs/1.21/client-libraries/#propagation-format&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Jaeger Trace Context&lt;/a&gt;, define specific header names and an encoding format for the header values.&lt;/p&gt;
&lt;p&gt;A trace context generally consists of, at least, a &lt;code&gt;trace_id&lt;/code&gt;, a &lt;code&gt;span_id&lt;/code&gt;, and a &lt;code&gt;sampled&lt;/code&gt; flag. The &lt;code&gt;trace_id&lt;/code&gt; is a unique identifier for the trace, the &lt;code&gt;span_id&lt;/code&gt; is a unique identifier for the request, and the &lt;code&gt;sampled&lt;/code&gt; flag is a boolean that indicates whether the request should be traced. For instance, the &lt;a href=&#34;https://www.w3.org/TR/trace-context/&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;W3C Trace Context&lt;/a&gt; defines the &lt;code&gt;Traceparent&lt;/code&gt; header, whose value contains a &lt;code&gt;trace_id&lt;/code&gt;, a &lt;code&gt;span_id&lt;/code&gt; and a &lt;code&gt;sampled&lt;/code&gt; flag, encoded as a dash (&lt;code&gt;-&lt;/code&gt;) separated list of hexadecimal values. When a trace context header is attached to an HTTP request, we refer to it as being &lt;em&gt;propagated&lt;/em&gt; to the downstream service.&lt;/p&gt;
&lt;h2 id=&#34;api&#34;&gt;API&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Class/Function&lt;/th&gt;
              &lt;th style=&#34;text-align: left&#34;&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-tempo/instrumenthttp/&#34;&gt;instrumentHTTP&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;Instruments the k6 http module with tracing capabilities.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/http-instrumentation-tempo/client/&#34;&gt;Client&lt;/a&gt;&lt;/td&gt;
              &lt;td style=&#34;text-align: left&#34;&gt;A configurable client that exposes instrumented HTTP operations and allows selectively instrumenting requests with tracing.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;This example demonstrates how to use the tracing API to instrument every HTTP request made in a script with tracing information.&lt;/p&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { check } from &amp;#39;k6&amp;#39;;
import tempo from &amp;#39;https://jslib.k6.io/http-instrumentation-tempo/1.0.1/index.js&amp;#39;;
import http from &amp;#39;k6/http&amp;#39;;

// instrumentHTTP will ensure that all requests made by the http module
// from this point forward will have a trace context attached.
//
// The first argument is a configuration object that
// can be used to configure the tracer.
tempo.instrumentHTTP({
  // possible values: &amp;#34;w3c&amp;#34;, &amp;#34;jaeger&amp;#34;
  propagator: &amp;#39;w3c&amp;#39;,
});

export default () =&amp;gt; {
  // the instrumentHTTP call in the init context replaced
  // the http module with a version that will automatically
  // attach a trace context to every request.
  //
  // Because the instrumentHTTP call was configured with the
  // w3c trace propagator, this request will as a result have
  // a `traceparent` header attached.
  const res = http.get(&amp;#39;http://httpbin.org/get&amp;#39;, {
    headers: {
      &amp;#39;X-Example-Header&amp;#39;: &amp;#39;instrumented/get&amp;#39;,
    },
  });
};&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="http-instrumentation-for-tempo">HTTP instrumentation for Tempo&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The source code for this library can be found in the &lt;a href="https://github.com/grafana/jslib.k6.io/tree/main/lib/http-instrumentation-tempo" target="_blank" rel="noopener noreferrer">grafana/jslib.k6.io&lt;/a> GitHub repository.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>The &lt;code>http-instrumentation-tempo&lt;/code> module allows you to &lt;em>instrument&lt;/em> HTTP requests so that they emit traces as the test runs. Use it to include a tracing context in HTTP requests, which can then be used by a tracing backend such as &lt;a href="/docs/grafana-cloud/testing/k6/analyze-results/integration-with-grafana-cloud-traces/">Grafana Tempo&lt;/a>.&lt;/p></description></item><item><title>utils</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/utils/</guid><content><![CDATA[&lt;h1 id=&#34;utils&#34;&gt;utils&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The source code for this library can be found in the &lt;a href=&#34;https://github.com/k6io/k6-jslib-utils&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;grafana/k6-jslib-utils&lt;/a&gt; GitHub repository.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;utils&lt;/code&gt; module contains number of small utility functions useful in every day load testing.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/check/&#34;&gt;check(val, sets, [tags])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Drop-in replacement for 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/k6/check/&#34;&gt;&lt;code&gt;check&lt;/code&gt;&lt;/a&gt; with support for async values.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/randomintbetween/&#34;&gt;randomIntBetween(min, max)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Random integer in a given range&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/randomitem/&#34;&gt;randomItem(array)&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Random item from a given array&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/randomstring/&#34;&gt;randomString(length, [charset])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Random string of a given length, optionally selected from a custom character set&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/uuidv4/&#34;&gt;uuidv4()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Random UUID v4 in a string representation&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/findbetween/&#34;&gt;findBetween(content, left, right, [repeat])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Extract a string between two surrounding strings&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/utils/normaldistributionstages/&#34;&gt;normalDistributionStages(maxVUs, durationSeconds, [numberOfStages])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Creates 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/k6-options/#stages&#34;&gt;stages&lt;/a&gt; which will produce a normal distribution (bell-curve) of VUs for a test&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;getCurrentStageIndex&lt;/td&gt;
              &lt;td&gt;Get the index of the running stage as defined in the &lt;code&gt;stages&lt;/code&gt; array options. It can be used only with the executors that support the &lt;code&gt;stages&lt;/code&gt; option as 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/ramping-vus/&#34;&gt;ramping-vus&lt;/a&gt; or 
    &lt;a href=&#34;/docs/k6/v2.3.x/using-k6/scenarios/executors/ramping-arrival-rate/&#34;&gt;ramping-arrival-rate&lt;/a&gt;.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;tagWithCurrentStageIndex&lt;/td&gt;
              &lt;td&gt;Tag all the generated metrics in the iteration with the index of the current running stage.&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;tagWithCurrentStageProfile&lt;/td&gt;
              &lt;td&gt;Tag all the generated metrics in the iteration with the computed profile for the current running stage.&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;simple-example&#34;&gt;Simple example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { sleep } from &amp;#39;k6&amp;#39;;
import http from &amp;#39;k6/http&amp;#39;;

import {
  randomIntBetween,
  randomString,
  randomItem,
  uuidv4,
  findBetween,
} from &amp;#39;https://jslib.k6.io/k6-utils/1.4.0/index.js&amp;#39;;

export default function () {
  const res = http.post(`https://quickpizza.grafana.com/api/users`, {
    username: `user_${randomString(10)}@example.com`, // random email address,
    password: uuidv4(), // random password in form of uuid
  });

  // find a string between two strings to grab the username:
  const username = findBetween(res.body, &amp;#39;&amp;#34;username&amp;#34;:&amp;#34;&amp;#39;, &amp;#39;&amp;#34;&amp;#39;);
  console.log(&amp;#39;username from response: &amp;#39; &amp;#43; username);

  sleep(randomIntBetween(1, 5)); // sleep between 1 and 5 seconds.
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="utils">utils&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The source code for this library can be found in the &lt;a href="https://github.com/k6io/k6-jslib-utils" target="_blank" rel="noopener noreferrer">grafana/k6-jslib-utils&lt;/a> GitHub repository.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>The &lt;code>utils&lt;/code> module contains number of small utility functions useful in every day load testing.&lt;/p></description></item><item><title>totp</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/totp/</guid><content><![CDATA[&lt;h1 id=&#34;totp&#34;&gt;totp&lt;/h1&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The source code for this library can be found in the &lt;a href=&#34;https://github.com/grafana/k6-jslib-totp&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;grafana/k6-jslib-totp&lt;/a&gt; GitHub repository.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code&gt;totp&lt;/code&gt; module provides TOTP (Time-based One-Time Password) generation and verification as defined in &lt;a href=&#34;https://datatracker.ietf.org/doc/html/rfc6238&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;RFC 6238&lt;/a&gt;.&lt;/p&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Class/Method&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/totp/totp/&#34;&gt;TOTP(secret, [digits])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Create a new TOTP instance&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/totp/gen/&#34;&gt;TOTP.gen([timeStep], [bias])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Generate a TOTP code&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/totp/verify/&#34;&gt;TOTP.verify(code, [timeStep])&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Verify a TOTP code&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;

export default async function () {
  const totp = new TOTP(&amp;#39;GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ&amp;#39;, 6);
  const code = await totp.gen();
  console.log(`TOTP code: ${code}`);

  const isValid = await totp.verify(code);
  console.log(`Valid: ${isValid}`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;with-k6-secrets&#34;&gt;With k6 Secrets&lt;/h2&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import secrets from &amp;#39;k6/secrets&amp;#39;;
import { TOTP } from &amp;#39;https://jslib.k6.io/totp/1.0.0/index.js&amp;#39;;

export default async function () {
  const secret = await secrets.get(&amp;#39;totp_secret&amp;#39;);
  const totp = new TOTP(secret, 6);
  const code = await totp.gen();
  console.log(`TOTP code: ${code}`);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
]]></content><description>&lt;h1 id="totp">totp&lt;/h1>
&lt;div class="admonition admonition-note">&lt;blockquote>&lt;p class="title text-uppercase">Note&lt;/p>&lt;p>The source code for this library can be found in the &lt;a href="https://github.com/grafana/k6-jslib-totp" target="_blank" rel="noopener noreferrer">grafana/k6-jslib-totp&lt;/a> GitHub repository.&lt;/p>&lt;/blockquote>&lt;/div>
&lt;p>The &lt;code>totp&lt;/code> module provides TOTP (Time-based One-Time Password) generation and verification as defined in &lt;a href="https://datatracker.ietf.org/doc/html/rfc6238" target="_blank" rel="noopener noreferrer">RFC 6238&lt;/a>.&lt;/p></description></item><item><title>k6-testing</title><link>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/</link><pubDate>Mon, 21 Sep 2026 15:16:28 +0000</pubDate><guid>https://grafana.com/docs/k6/v2.3.x/javascript-api/jslib/testing/</guid><content><![CDATA[&lt;h1 id=&#34;k6-testing&#34;&gt;k6-testing&lt;/h1&gt;
&lt;p&gt;The k6 testing library provides assertion capabilities for both protocol and browser testing, and draws inspiration from &lt;em&gt;Playwright&lt;/em&gt;&amp;rsquo;s test API design.&lt;br /&gt;
The entire library is centered around the 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/expect/&#34;&gt;&lt;code&gt;expect()&lt;/code&gt;&lt;/a&gt; function, which can be configured for convenience.&lt;/p&gt;


&lt;div class=&#34;admonition admonition-note&#34;&gt;&lt;blockquote&gt;&lt;p class=&#34;title text-uppercase&#34;&gt;Note&lt;/p&gt;&lt;p&gt;The k6 testing library source code is available on &lt;a href=&#34;https://github.com/grafana/k6-jslib-testing&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;&lt;/blockquote&gt;&lt;/div&gt;

&lt;h2 id=&#34;features&#34;&gt;Features&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;https://playwright.dev/docs/test-assertions&#34; target=&#34;_blank&#34; rel=&#34;noopener noreferrer&#34;&gt;Playwright-inspired assertions&lt;/a&gt;&lt;/strong&gt;: API designed with patterns inspired by Playwright&amp;rsquo;s testing approach&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;#demo&#34;&gt;Protocol and browser testing&lt;/a&gt;&lt;/strong&gt;: Works with both HTTP/API testing and browser automation&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/expect/#retrying-assertions&#34;&gt;Auto-retrying assertions&lt;/a&gt;&lt;/strong&gt;: Automatically retry assertions until they pass or timeout&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/expect/#soft-assertions&#34;&gt;Soft assertions&lt;/a&gt;&lt;/strong&gt;: Continue test execution even after assertion failures&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/configure/&#34;&gt;Configurable timeouts&lt;/a&gt;&lt;/strong&gt;: Customizable timeout and polling intervals&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;usage&#34;&gt;Usage&lt;/h2&gt;
&lt;p&gt;To use the testing library in your k6 script, import it in your tests directly from the jslib repository:&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;demo&#34;&gt;Demo&lt;/h2&gt;
&lt;h3 id=&#34;protocol-testing&#34;&gt;Protocol Testing&lt;/h3&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { check } from &amp;#39;k6&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;
import { randomString } from &amp;#39;https://jslib.k6.io/k6-utils/1.4.0/index.js&amp;#39;;
import http from &amp;#39;k6/http&amp;#39;;

export default function () {
  const payload = JSON.stringify({
    username: `${randomString(5)}_default@example.com`,
    password: &amp;#39;secret&amp;#39;,
  });
  const response = http.post(`https://quickpizza.grafana.com/api/users`, payload); // create user

  console.info(response.json());

  //Traditional k6 check
  check(response, {
    &amp;#39;status is 201&amp;#39;: (r) =&amp;gt; r.status === 201,
  });

  //Using expect assertions
  expect(response.status).toBe(201);
  expect(response.json()).toHaveProperty(&amp;#39;id&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;browser-testing&#34;&gt;Browser Testing&lt;/h3&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { browser } from &amp;#39;k6/browser&amp;#39;;
import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

export const options = {
  scenarios: {
    ui: {
      executor: &amp;#39;shared-iterations&amp;#39;,
      options: {
        browser: {
          type: &amp;#39;chromium&amp;#39;,
        },
      },
    },
  },
};

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

  await page.goto(&amp;#39;https://quickpizza.grafana.com&amp;#39;);

  // Retrying Assertions
  await expect(page.locator(&amp;#39;h1&amp;#39;)).toBeVisible();
  await expect(page.locator(&amp;#39;h1&amp;#39;)).toHaveText(&amp;#39;Looking to break out of your pizza routine?&amp;#39;);
}&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;configuration&#34;&gt;Configuration&lt;/h2&gt;
&lt;p&gt;Create configured 
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/configure/&#34;&gt;&lt;code&gt;expect.configure()&lt;/code&gt;&lt;/a&gt; instances for custom behavior:&lt;/p&gt;
&lt;!-- md-k6:skip --&gt;

&lt;div class=&#34;code-snippet &#34;&gt;&lt;div class=&#34;lang-toolbar&#34;&gt;
    &lt;span class=&#34;lang-toolbar__item lang-toolbar__item-active&#34;&gt;JavaScript&lt;/span&gt;
    &lt;span class=&#34;code-clipboard&#34;&gt;
      &lt;button x-data=&#34;app_code_snippet()&#34; x-init=&#34;init()&#34; @click=&#34;copy()&#34;&gt;
        &lt;img class=&#34;code-clipboard__icon&#34; src=&#34;/media/images/icons/icon-copy-small-2.svg&#34; alt=&#34;Copy code to clipboard&#34; width=&#34;14&#34; height=&#34;13&#34;&gt;
        &lt;span&gt;Copy&lt;/span&gt;
      &lt;/button&gt;
    &lt;/span&gt;
    &lt;div class=&#34;lang-toolbar__border&#34;&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;div class=&#34;code-snippet &#34;&gt;
    &lt;pre data-expanded=&#34;false&#34;&gt;&lt;code class=&#34;language-javascript&#34;&gt;import { expect } from &amp;#39;https://jslib.k6.io/k6-testing/0.6.1/index.js&amp;#39;;

// Create configured expect instance
const myExpect = expect.configure({
  timeout: 10000, // Default timeout for retrying assertions
  interval: 200, // Polling interval for retrying assertions
  colorize: true, // Enable colored output
  display: &amp;#39;pretty&amp;#39;, // Output format
  softMode: &amp;#39;fail&amp;#39;, // Soft assertion behavior
});&lt;/code&gt;&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;assertion-types&#34;&gt;Assertion types&lt;/h2&gt;
&lt;p&gt;The testing library provides two types of assertions:&lt;/p&gt;
&lt;h3 id=&#34;non-retrying-assertions&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/&#34;&gt;Non-Retrying Assertions&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Synchronous assertions that evaluate immediately. These are ideal for testing static values, API responses, and scenarios where the expected condition should be true at the moment of evaluation.&lt;/p&gt;
&lt;h3 id=&#34;retrying-assertions&#34;&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/&#34;&gt;Retrying Assertions&lt;/a&gt;&lt;/h3&gt;
&lt;p&gt;Asynchronous assertions that automatically retry until conditions become true or timeout. These are suitable for browser testing, dynamic content, and scenarios where conditions may change over time.&lt;/p&gt;
&lt;h2 id=&#34;api-reference&#34;&gt;API Reference&lt;/h2&gt;
&lt;section class=&#34;expand-table-wrapper&#34;&gt;&lt;div class=&#34;button-div&#34;&gt;
      &lt;button class=&#34;expand-table-btn&#34;&gt;Expand table&lt;/button&gt;
    &lt;/div&gt;&lt;div class=&#34;responsive-table-wrapper&#34;&gt;
    &lt;table&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Function&lt;/th&gt;
              &lt;th&gt;Description&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/expect/&#34;&gt;expect()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Main assertion function&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/configure/&#34;&gt;expect.configure()&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Create configured expect instances&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/non-retrying-assertions/&#34;&gt;Non-Retrying Assertions&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Synchronous assertions for immediate evaluation&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr&gt;
              &lt;td&gt;
    &lt;a href=&#34;/docs/k6/v2.3.x/javascript-api/jslib/testing/retrying-assertions/&#34;&gt;Retrying Assertions&lt;/a&gt;&lt;/td&gt;
              &lt;td&gt;Asynchronous assertions for dynamic content&lt;/td&gt;
          &lt;/tr&gt;
      &lt;/tbody&gt;
    &lt;/table&gt;
  &lt;/div&gt;
&lt;/section&gt;]]></content><description>&lt;h1 id="k6-testing">k6-testing&lt;/h1>
&lt;p>The k6 testing library provides assertion capabilities for both protocol and browser testing, and draws inspiration from &lt;em>Playwright&lt;/em>&amp;rsquo;s test API design.&lt;br />
The entire library is centered around the
&lt;a href="/docs/k6/v2.3.x/javascript-api/jslib/testing/expect/">&lt;code>expect()&lt;/code>&lt;/a> function, which can be configured for convenience.&lt;/p></description></item></channel></rss>