k6

HTTP request to retrieve all embeded resources

In jmeter, there is an option to allow the HTTP request to retrieve all embeded resources. How can I write the code in k6?

Hi @xyngfei,
I would advice that you record your session in the browser and than use the generated file.

Alternatively you can parse the html and then make batch requests for the parts you want, but that will be … much harder and error prone. Also won’t catch any cases where because of JS on the page somethings have been loaded (I suppose jmeter misses those as well though).

So session recording and possibly manual editing of the script will be “much” easier to do.

I did try to use the loadimpact chrome extension, however some of the filename resources is very unique. How do i overcome this issue?
https://support.loadimpact.com/3.0/user-scenarios/load-impact-chrome-extension/

image

Not sure I understand what you mean about unique filename resources, but the link you’ve pasted is for the old chrome extension. This is the new one: https://support.loadimpact.com/4.0/guides/load-impact-version-4-chrome-extension/
And the link @mstoykov sent describes how to record HAR files without the extension: https://docs.k6.io/docs/session-recording-har-support

1 Like

@nedyalko

Thanks for your info.
However, the HAR recording doesn’t solve the unique filename issue which is generated by the webpack bundle. Do you have any better way to handle this issue?

Sorry for the late reply. In essence, if you have dynamic file names, you’d have to modify the resulting JS code to handle these cases. Specifically, as @mstoykov also pointed out, if the dynamic path to the webpack bundle is in a <script> tag, you can probably extract it by using the k6 HTML parsing API: https://docs.k6.io/docs/parsehtml-src

Thanks @nedyalko

For others info, you can use the method below to get all the script src info:-

const req_script = parseHTML(res.body);
req_script.find(‘script’).toArray().forEach(function (item) {
console.log(item.attr(‘src’));
// do something
});

1 Like