Load tests should be realistic. One way to create a realistic test is to use a recording of a user session. You can then use this recording to model the logic of your test.
k6 provides two tools that can directly convert a recording into k6 script:
- Browser recorder generates a k6 script from a browser session. Available for Chrome and Firefox.
- HAR converter generates a k6 script from the requests included in a HAR file.
Record instead of scripting
The recording process has three steps:
- Record a user or API session.
- Convert the recorded session into a test.
- Run the test.
Recordings show the sequence of the session's requests and parameters, helping testers quickly build complex chains of requests. For this reason, testers commonly use recordings while testing complex scenarios on websites or mobile applications.
Suppose you have to create a performance test that simulates a user journey with dozens or hundreds of requests. In such a case, the recording lets you avoid writing the test from scratch.
Be sure to record realistically
Before you record your session, consider the following dos and don'ts.
It's a good idea to:
- Browse as a user would
- Take natural pauses that users would take to consume page content
- Focus on the most common use cases, rather than all the possible use cases
- Take note of pages where forms/logins occur. You will likely need to complete some scripting.
You probably do not want to:
- Visit every page in one journey
- Click every possible option
- Navigate as fast as you can
- Navigate out of your actual site or application