Locust Directory

WordPress Load Test Example

Load test a WordPress based Blog or CMS with automatic crawling

Overview

Load testing (aka stress testing) your WordPress Blog or CMS is made extremely easy by LoadForge, and you can test it with a free account today. We are going to be showing how to simulate a real set of users, browsing through your latest blog posts at random.

We have a full WordPress load testing guide available as well.

The nicest feature about this test is that it will automatically crawl valid URLs and then request them like a real user, at random. This can be applied to many types of tests.

Code

from locust import HttpUser, task, between
from pyquery import PyQuery
import random

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

    def index_page(self):
        r = self.client.get("/blog/")
        pq = PyQuery(r.content)

        link_elements = pq(".blog-list-post h2 a")
        self.blog_urls = []

        for l in link_elements:
          if "href" in l.attrib:
            self.blog_urls.append(l.attrib["href"])

    def on_start(self):
        self.index_page()

    @task(1)
    def static_content(self):
        # images
        self.client.get("/img/logo/logo.png")
        self.client.get("/img/images/cta_img.png")
        self.client.get("/img/logo/logo.png")
        self.client.get("/img/images/footer_fire.png")
        # styles
        self.client.get("/css/compiled.css?id=629e6d86d0748098936a")
        # scripts
        self.client.get("/js/compiled.js?id=1a927dbcfa8d96520959")

    @task(3)
    def blog_post(self):
        url = random.choice(self.blog_urls)
        r = self.client.get(url)


    @task(3)
    def home_page(self):
        self.client.get("/blog/")        


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.