I am trying to simulate a form submission using Locust in Python. When manually submitting the form in a browser with incomplete data, I see the expected validation message: "Please make sure all fields are correctly filled in!"
. However, when I simulate the same form submission using Locust, the message does not appear in the response.text
.
URL – https://www.globalsqa.com/
Steps
-
Manual Testing:
-
I opened the form page in a browser.
-
Navigate to the Contacts Us page
-
I filled in the form with incomplete data.
-
Upon submitting, the validation message
"Please make sure all fields are correctly filled in!"
appeared, indicating that the server correctly detects the incomplete data.
-
-
Locust Simulation:
-
I wrote a Locust script to simulate the form submission with the same incomplete data.
-
The form is submitted via a POST request, but the expected validation message is not present in the
response.text
. -
Instead, the submission seems to be processed as if no validation error occurred.
-
Here’s the Locust test script I’m using:
from locust import HttpUser, task, between
class DemoTest(HttpUser):
wait_time = between(1, 5) # Users will wait between 1 and 5 seconds between tasks
@task
def load_homepage(self):
print("Loading Home page")
res = self.client.get("/")
print("res status_code home page:", res.status_code)
@task
def load_contact_us(self):
print("Loading Contact Us page")
headers = {'Accept': 'text/html'}
res = self.client.get("/member/login", headers=headers)
print("res status_code contact us page:", res.status_code)
print("res url:", res.url)
print("res headers:", res.headers)
@task
def submit_contact_form(self):
form_url = "/contact-us/"
form_data = {
"comment_name": "John Doe",
"email": "johndoe@example.com",
"subject": "Test Subject",
"comment": "This is a test message from Locust."
}
print("Submitting contact form")
response = self.client.post(form_url, data=form_data)
if response.status_code == 200:
print("Form submission successful (200 OK)")
# Check for expected validation message
if "Please make sure all fields are correctly filled in!" in response.text:
print("Validation message displayed: 'Please make sure all fields are correctly filled in!'")
else:
print("Form submission was processed, no validation errors detected.")
Even though I expect the validation message "Please make sure all fields are correctly filled in!" to appear after the form submission, it doesn’t show up in response.text.
Questions:
Am I missing something in my form data or request setup that could prevent the validation message from appearing?
Is there a better way to debug or inspect the actual server response to understand why this message is missing?
Could this issue be related to server-side form validation logic, and if so, how can I simulate this more accurately?
Any help would be appreciated!
You need to sign in to view this answers
Leave feedback about this