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

post( url, [body], [params] )

Make a POST request.

Parameter
Type
Description

url

string

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

body

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",
  };
  let headers = { "Content-Type": "application/x-www-form-urlencoded" };
  // Send login request
  res = http.post(baseURL + "/user/login", formdata, { headers: headers });
  // Verify that we ended up on the user page
  check(res, {
    "login succeeded": (res) => res.url == `${baseURL}/users/testuser1`,
  }) || fail("login failed");
}

Using http.post() to perform a user login at an E-commerce site

post( url, [body], [params] )