Question on http.get

I have some quick questions about the k6/http.get.

Does http.get( get all embeded CSS, JS, and images or just the HTML document of index.html only?

If http.get also get all included CSS, imanges, is there a way for http.get to determine if it has already downloaded it and not to download it again until the cache expired?

Thank you.

No. k6/http is a library for performing HTTP/HTTPS transactions, it’s not an interpreter for HTML or CSS. In general, it’s not a browser.

That’s leading to your next question about whether it supports caching. Unfortunately, the answer to that is no.

So when the k6/http get an URL, it only get the content of the request page and not other media associated to it. Is there a way to mimic browser behavior in the load impact API?

Thanks in advance.

Unfortunately, there’s no way for now (and maybe not in the near future).

The k6/http library, like most other http libraries (go’s net/http, python’s requests …) aim to implement HTTP client. A browser needs an HTTP client to work, but not the other way around.

You can also use parseHTML( src ) to parse the HTML response body, then you it to load all images and scripts.

What’s your goal with testing? http.get() alone will only load the URL specified. However, if you are looking to test a user journey on a website, you may want to use the HAR-to-k6 converter to capture the additional requests. When using the converter you’ll notice that the main HTML is generally put into it’s own get, then additional assets are placed into a http.batch(). This results in that test emulating browser behavior from a request standpoint (requests in a batch are made in parallel up to limits specified in the batch/batchPerHost options). If you are using the LoadImpact cloud, we also have a chrome extension to aid in turning browser sessions → tests scripts. In short, it basically creates and converts a HAR file for you. I see many users use either option to create a “base script” when testing user journeys in web apps and websites, then they add additional logic to handle dynamic tokens, parameterize data, etc.

One last important thing to note, k6 (and LoadImpact) will never execute client side code nor render anything. We make requests and receive full responses. Going back to the above, CSS gets loaded, but not rendered. JS gets loaded, but not executed.

1 Like

This is awesome! Thanks for the explanation and recommendation, Mark! :slight_smile:

Hello, cuonglm. Can you describe how to parse img links with parsehtml? Thank you in advvance