How to run a load test against multiple web pages with specific number of VUs?

I am new to k6 load testing. And I have been asked to test the performance of multiple pages with 20 VUs. How should I construct the tests?

Currently I am listing them in the default function and have a list of batch requests for each page. Am I doing it correctly with following example?

Example:
export let options = {
stages: [
{ duration: “1m”, target: 20 },
{ duration: “5m”, target: 20 },
{ duration: “1m”, target: 0 }
]

group(“Test performance of 3 pages with 20 VUs”, function() {
//3 request for 3 test pages
let req, req2, req3;
req = [{
“method”: “get”, home page

req2 = [{
“method”: “get”, listing page

req3 = [{
“method”: “get”, support page

http.batch(req);
http.batch(req2);
http.batch(req3);
});
}

And I have following questions:

  1. By doing it this way when at its peak where 20 VUs are reached, it is possible that at some point 5 VUs might be hitting page 1, 5 other VUs hitting page 2 and the rest 10 VUs hitting page 3. So we cannot get the concurrency of 20 VUs hitting the same page. How do we address this? I have tried using http.batch(req, req2, req3); to have the VUs hitting all the pages at the same time, but it doesn’t seem to give you the analytics for each page.

  2. Our pages have asynchronous elements. Does k6 evaluate the load time of the main doc, or does it include those asynchronous elements as well, eg, those making javascript calls to load certain datatable? Should those be included in evaluating the performance of these pages?

  1. I am not sure I understand exactly what you are asking, but please take a look at the scenarios feature that newer k6 versions support and the examples there. Using scenarios and the different available executors, you should be able to achieve pretty much any load pattern you desire.
  2. k6 is not a web browser, so it doesn’t actually evaluate the HTML or JavaScript in a web page and load any page elements referenced by them. You have to specify any such elements in your script yourself. To help with that, you can record the requests your browser makes while actually browsing the website in a .har file and then convert that .har file to a k6 script. For more details, see Using the HAR converter