0

New to k6, working with a web application that presents a spinner briefly on the home page while css and js files load.

Once the files are loaded and scripts are available, a login form is added (replacing the spinner).

  • With k6, is there a way to wait until a specific body element (the login form) is available in the body before continuing with the next step (ie. populating the username and pwd and submitting the form to login)?

Currently, when I review the response body, I see the spinner element only. Adding a delay does not appear to affect the body returned, even though the login form should, in theory, have been added to the page.

If the element is added to the body after the initial page load, will it be detected by k6 and made available in the response?

Thanks for your help.

Bill

Bill R
  • 1
  • 3

2 Answers2

1

k6 doesn't work like a browser - the load tests are written in JavaScript, but when you request an HTML file, the JavaScript in that file isn't executed. It usually can't be executed even with eval() or something like that, since k6 doesn't have a DOM or any of the usual browser APIs. So you have to explicitly specify any HTTP requests you want your k6 scripts to make, and in your case I assume that the spinner and login form are generated by a JavaScript somewhere in the home page.

To simplify working with such highly dynamic websites when you use k6, you can use the site normally in your browser, record the browser session as a .har file and export it, and then convert that .har file to a k6 script with the k6 convert command like this: k6 convert session.har -O k6_script.js. You can find more information about the whole process here.

na--
  • 1,016
  • 7
  • 9
  • Excellent! This appears to have worked. Now I need to spend some time digging through the converted .har, fine-tuning things and learning how to use k6 in more detail. Thanks for the tip! – Bill R Oct 02 '18 at 14:24
  • I'm using the [InfluxDB output with Grafana to visualize results](https://docs.k6.io/docs/results-output#section-influxdb-output) as well -- nice tool combo. – Bill R Oct 02 '18 at 14:30
  • After a deeper look at the results and additional testing, it appears the recording didn't pick up the full process (ie. waiting for the login form to be added to the page, submitting the form, logging in, etc.). I will keep tinkering to see it I can get this to work, but, sadly, I may have to go a different direction. – Bill R Oct 02 '18 at 15:20
0

k6 doesn't execute client side code, nor does it render anything. It makes requests against the target system and loads them. This makes it efficient to make a large number of reqeusts, but creates new things that must be solved in certain cases.

  1. Capturing all the requests necessary - typically using the k6 convert to convert a HAR file works well to give a foundation of a script. I suggest using the other options in converting to limit any third party requests. e.g. --only or --skip. More info here: https://support.loadimpact.com/4.0/how-to-tutorials/how-to-convert-har-to-k6-test/

  2. Since you recorded your browser session, if your application/site uses anything to prevent CSRF attacks, you must handle those values/correlate them. e.g. .NET sites use VIEWSTATE, if you were testing a .NET app, you would need to instruct the VUs to extract the viewstate from the response body and reuse it in your requests that require it

  3. In a similar vein to point 2, if you are submitting a form, you probably don't want to utilize the same details over and over again. That typically just tests how well your system can cache or results in failing requests (if you are logging in and your system doesn't support concurrent logins for the same user as one example). k6 is able to utilize CSV or JSON data as a source for data parameterization. You can also generate some of this inline if it's not too complex. Some examples are here: https://docs.k6.io/docs/open-filepath-mode

  • Thanks for the suggestions! k6 may end up being a good solution for load testing the API but due to the dynamic / interactive nature of the website itself, it looks like Selenium may need to be part of the load testing mix. – Bill R Oct 03 '18 at 13:23