Test guides
Submitting forms
Testing form submissions is a crucial part of load testing. Applications often rely on form inputs for various functions, including user registration, login, feedback, and more. In this documentation, we'll explore how to simulate these activities with LoadForge using the locust.io
platform.
There are different methods and data types used in submitting forms, ranging from traditional multipart web forms to submitting JSON data. Let's walk through these different methods.
Tip
Record and Replay with LoadForge
One of the key features of LoadForge is its ability to record your browser interactions and replay them during the test. This feature simplifies capturing form submissions, ensuring that you're testing real-world user interactions.
Submitting Standard Web Forms
A standard web form usually involves sending data as part of a POST
request. Here's a guide on how to simulate the submission of a standard form to an endpoint, for example, /contact
.
Example: Submitting a Contact Form
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
@task(2)
def contact(self):
self.client.post("/contact", {
'email': 'user@domain.com',
'subject': 'Hello from LoadForge!',
'message': 'This is a sample message sent during a LoadForge test.'
})
For further insights and advanced use-cases on this type of form submission, refer to:
Submitting JSON Data
In modern web applications, interacting with APIs often involves sending and receiving JSON data. Here's how you can set up a task in LoadForge to send a JSON payload.
Example: JSON Data POST Request
import json
from locust import HttpUser, task, between
class QuickstartUser(HttpUser):
wait_time = between(3, 5)
@task(1)
def post_json(self):
payload = {
'key': 'value',
'question': 'answer123'
}
headers = {'content-type': 'application/json'}
response = self.client.post("/post/endpoint", data=json.dumps(payload), headers=headers)
For more details and variations on submitting JSON data, check out:
By understanding these methods, you'll be well-equipped to create varied and comprehensive load tests for your applications using LoadForge. Happy testing!