Locust Directory

Checking Response Text and Time

Check for a specific word in the result, and that it doesn't take over 0.5 seconds.

Overview

Here we can see a snippet that checks for the word "Success" in a response, and then generates a failure if its taken more than half a second to reply.

This is useful as it shows an example of monitoring the actual timings around a response. With LoadForge you can parse the content that comes back, read headers, monitor timings and more.

This test will report failures in your LoadForge test when anything is slow.

Code

import time
from locust import HttpUser, task, between

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

    @task(1)
    def index_page(self):        
        with self.client.get("/", catch_response=True) as response:
            if response.text != "Success":
                response.failure("Got wrong response")
            elif response.elapsed.total_seconds() > 0.5:
                response.failure("Request took too long")    


This guide is part of the LoadForge Directory, an index of locustfile's for use with LoadForge website and API load tests. We also provide a wizard to generate tests, and onboarding assistance for clients. Contact us should you have any questions.

LoadForge provides load testing and stress tests for websites, APIs and servers. It uses your cloud account to rapidly scale large numbers of simulated users to load test your website, store, API, or application for cheap - just cents per test!

For more help on Tests please see our official documentation. Logged in users can also use our wizard to generate a locustfile, or you can record your browser steps.

Ready to run your test?
Start your first test within minutes.