Test guides

Submitting forms

Submitting forms is a very common activity during load tests. From input in your application, to logging in, and more.

There are also multiple types of "submitting forms" from true multipart web forms to submitting JSON data and everything in-between.

Record your browser

Remember that with LoadForge you can record your browser and replay it as a test. Allowing you to easily capture forms :)

Standard Form

Below is an example for submitting a standard form request to /contact.

from locust import HttpUser, task, between


class QuickstartUser(HttpUser):


    @task(2)
    def contact(self):
        self.client.post("/contact", {
            'email': 'user@domain.com',
            'subject': 'Hi there I am LoadForge :)',
            'message': 'I am a message from LoadForge'
        })

You can learn more about this type of form submission on the following recommended resources:

JSON data

You may want to post JSON data as well. Below is a simple example of that:

import time, json
from locust import HttpUser, task, between


class QuickstartUser(HttpUser):
    wait_time = between(3, 5)


    @task(1)
    def api_page(self):
        payload = {
            'key': 'value'
            'question': 'answer123'
        }


        headers = {'content-type': 'application/json'}
        response = self.client.post("/post/endpoint", data=json.dumps(payload), headers=headers

You can learn more about this type of form submission on the following recommended resources:

Previous
Custom shapes