k6

A modern load testing tool, using Go and JavaScript

"like unit testing, for performance"

k6 is a modern load testing tool, building on Load Impact's years of experience. It provides a clean, approachable JavaScript scripting API, distributed and cloud execution, and orchestration via a REST API.

Get Started    Documentation

Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

request( method, url, [body], [params] )

Make an HTTP request.

Parameter
Type
Description

url

string

Request URL (e.g. "http://example.com").

body (optional)

string | object

Request body; objects will be query encoded.

params (optional)

object

Params object containing additional request parameters.

Returns:

Type
Description

Response

HTTP Response object.

import http from "k6/http";
import { check, fail } from "k6";

export let options = { maxRedirects: 10 };

const baseURL = "https://dev-li-david.pantheonsite.io";

export default function() {
  // Fetch the login page, with the login HTML form
  let res = http.get(baseURL + "/user/login");
  // Extract hidden value needed to POST form
  let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
  // Create an Object containing the form data
  let formdata = {
    name: "testuser1",
    pass: "testuser1",
    form_build_id: formBuildID,
    form_id: "user_login",
    op: "Log in",
  };
  // Use http.request to send login POST request
  res = http.request(
    "POST",
    baseURL + "/usr/login",
    formdata,
    { headers: { "Content-Type": "application/x-www-form-urlencoded" } },
  );
  // Verify that we ended up on the user page
  check(res, {
    "login succeeded": (res) => res.url == `${baseURL}/users/testuser1`,
  }) || fail("login failed");
}

Using http.request() to issue a POST request, logging in to an e-commerce site

request( method, url, [body], [params] )