Overview
While testing, it’s crucial to simulate user behavior as realistically as possible. One key aspect of this simulation is introducing waits or pauses that a typical user might experience, like reading a webpage or waiting for some data. By default, LoadForge’swait_time
attribute allows you to set such pauses. This guide will delve deeper into customizing these waits and understanding their applications.
wait_time vs. time.sleep
There are two primary ways to introduce waits in your tests:-
wait_time
: This attribute specifies the pause between tasks. For example, onceload_page
concludes, the simulated user would wait for the duration specified bywait_time
before initiating the next task. In our example below, after theload_page
task concludes, a user will pause for a duration anywhere between 10 to 20 seconds. -
time.sleep
: This function allows for more specific pauses, right at the point it’s called within your test. So if you want a user to pause immediately after a particular HTTP request and before another,time.sleep
can be used.
Example Code
Here’s an example:/page1
, waiting for a duration between 10 to 60 seconds (perhaps reading content or interacting with elements), and then navigating to /page2
, where they pause again for a fixed 20 seconds.
LoadForge leverages the power of the open-source
locust
library. This means that if you’re already a locust user, you can directly port this script. If you wish to amplify your testing capabilities, consider importing your script into LoadForge!