Knowledgebase

Filling and Submitting HTML Forms


Background

Scripting example on how to handle HTML forms in a load test.


HTML

Filling in and submitting forms

One of the most tedious tasks when testing websites and apps is to get all the form filling to work. You have to get all the so called “correlations” (see above) correct which can take time, even with the help of a scenario recorder as the staring point for getting the basic user journey down into a re-playable test.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import http from "k6/http";
import {sleep} from "k6";

export default function() {
    // Request page containing a form
    let res = http.get("https://httpbin.org/forms/post");
 
    // Now, submit form setting/overriding some fields of the form
    res = res.submitForm({
        formSelector: 'form[action="/post"]',
        fields: { custname: "test", extradata: "test2" },
        submitSelector: "mySubmit",
    });

    sleep(3);
}

Relevant k6 APIs: