No results for

Powered byAlgolia

HTML Forms

Scripting example on how to handle HTML forms.

In many cases using the Selection API (jQuery API clone) to interact with HTML data is enough, but for some use cases, like with forms, we can make things easier providing a higher-level API like the Response.submitForm( [params] ) API.

submit-form.js
1import http from 'k6/http';
2import { sleep } from 'k6';
3
4export default function () {
5 // Request page containing a form
6 let res = http.get('https://httpbin.test.k6.io/forms/post');
7
8 // Now, submit form setting/overriding some fields of the form
9 res = res.submitForm({
10 formSelector: 'form',
11 fields: { custname: 'test', extradata: 'test2' },
12 });
13 sleep(3);
14}

Relevant k6 APIs: