k6

Question on http.get

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

Does http.get(http://somedomain.com/index.html) 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, CSS … In general, it’s not a browser.

That’s leading to your next question that supporting for caching the response doesn’t support, too.

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).

k6 http library, like most other http library (Go net/http, Python requests …) aim to implement HTTP client. A browser consist a HTTP client but not vice versa.

You can also use https://docs.k6.io/docs/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.