I have a POST request normally it brings the 200 response code for successful request. The behavior of the request initiate several other request to download static, and supporting html files along with the main response, like below;
But while running on K6 it shows only one main response (no static or other supporting files not downloaded). It effects the actual response time for the particular request.
Note : Subsequent request dynamically changes based on the condition.
How to handle it.
if the response body of the initial request is HTML, then the browser will make subsequent requests as indicated by the HTML. This is why you see those requests to fetch static assets.
k6, however, does not work like a browser. It works on the HTTP API level, so if you make a POST request, you would have to read the response body and script those additional requests yourself.
You do have a few options though:
You can use a browser recorder extension that will generate a k6 script for you, which will include those additional requests.
Export a HAR file from your browser session and convert it to a k6 script using the HAR converter, which will have similar results to the above.
Give xk6-browser a try. It’s an extension for k6 that allows you to script user interactions within a Chrome browser, which would also make those additional requests. Just be aware that this end-to-end browser testing is a different concept to API testing, as you’re testing the application as a real user would (as opposed to k6’s virtual users), which might or might not be what you want. And keep in mind that the extension is still in early stages of development, so it might not work properly in some scenarios, but the basic functionality is there.
Captured the fetching request URLs (images, css and JS), but i need to send it on parallel request. how can i parameterize the dynamically changing get request calls on batch request.
Or any other options like JMeter or Gatling (
how can i parameterize the dynamically changing get request calls on batch request.
Can you share your script and what you’re having difficulties with? The
http.batch() documentation shows several examples of how it could be used to send requests in parallel.
There is no feature in k6 similar to Gatling’s
inferHtmlResources. Like I explained above, you would have to manually read the response HTML and assemble the array of requests to pass to
Response.html() could help you with this.
Though really this would be much easier if you used the browser recorder extension and then tweaked the generated script as needed.
Hi @imiric ,
I can able to read the HTML report and capture requests, but facing some issues to implement.
Problem 01: There is more than one request, but i can able to capture only one request. For my scenario I need to capture all the img src links . Guide me on this if i need to change the below snippet.
let doc = JSON.parse(response.body);
let myhtml= JSON.stringify(doc.message);
const srcs = findBetween(myhtml, '<img src=\'', "\'");
Problem 02: How can I construct the request array based on the above input.
I think you’ll have a very hard time doing this manually.
findBetween() does a simple string-based match, so it’s not well suited for what you need here. You might want to take a look at
Response.html() that will allow you to make lookups using CSS selectors.
Though even with the Selection API this would be very tedious to write manually. Is there a reason you don’t use the browser recorder extension?
As for constructing the array, you’ll need to loop over all the elements you find and
Array.push() each URL, along with other parameters. See the documentation.