I am trying to load test a few pages on a website. Those pages contains some ajax requests, but I don’t know how to execute them in the load test script.
After some searching on the internet, it seems the only way to do it was to capture the ajax requests of the test page through recording a session and then put them in the load test script.
But then I need to replace the session key, cookie and sometimes POST’s body data dynamically in the script. If there’s update in the test page, I have to re-capture the ajax requests again. It looks like not a practical approach.
Could anyone please give me some advice on how to do it more ‘automated’ way? Many thanks
In general, testing highly dynamic and JS heavy sites can become cumbersome using API testing tools like standard k6. You might be able to use that recorded script and parametrize what you need to get it to work, but it’s not straightforward as you’ve found out.
You might want to consider writing a browser-based test instead using xk6-browser. This is a k6 extension that allows you to write higher level tests that drive a browser, so instead of trying to simulate individual Ajax calls, you can just navigate to the page and let the browser do the work for you, exactly like it would for a real world user.
Note that this type of test generally isn’t useful for load testing, simply because it’s quite resource intensive to run many browser instances on a single machine. But you might find it useful for writing functional and end-to-end tests if you have a very dynamic site.
And also note that xk6-browser is still in early beta stages, so you might run into some issues, which we’d appreciate if you let us know via this subforum or by creating a new GitHub issue.