Codeless load generation for non-technical team members

Hi, so to make ease of use for the non-technical members I want to make a codeless load generator.
I’ve made an example and will be glad to get your opinion about if that is a good practice? is there any better-suggested way to do a codeless load generator?

Thanks!

I was thinking of making a JSON structure like this:

[
  {
    "type": "GET",
    "url": "https://https://test.k6.io/contacts.php"
  },
  {
    "type": "GET",
    "url": "https://test.k6.io/news.php"
  },
  {
    "type": "POST",
    "url": "https://test.k6.io/login.php",
    "headers": {
      "Content-Type": "application/json"
    },
    "body": {
      "login": "test", "password": "test"
    }
  }
]

and then loading the JSON file and generating execution like that:

// init context: load requests definition
const requests = new SharedArray("load data", function () {
  return JSON.parse(open("./load.json"));
});

export function test(data) {
  group(`Test execution`, function () {
    for (const [i, req] of requests.entries()) {
      if (req.type === "GET") {
        const response = http.get(req.url);
        check(response, { "is status 200": (r) => r.status === 200 });
      }
      if (req.type === "POST") {
        let response;
        if (req.headers) {
          response = http.post(req.url, req.body, req.headers);
        } else {
          response = http.post(req.url, req.body);
        }
        check(response, { "is status 200": (r) => r.status === 200 });
      }
    }
  });
}
1 Like

Hi @ValorHeart,

I personally am not certain that “non-technical” team members will be better off just being able to make requests instead of writing the code which does it. It definitely lowers the boundary, but in my person experience, the problem isn’t not being able to write tests due to lack of technical skill. But being able to understand the results or what needs to happen even without the need to be able to write code.

I also don’t think that writing JSON by hand will be a thing “non-technical” people will have no problems. On the opposite I expect that all the missed or extra commas will likely drive them mad ;).

Having said that there are a bunch of workaround which at least get around the JSON part :person_shrugging: :

  1. You can browser record and use the har converter - obviously only applicable for things browsers can do. The har format is a JSON as well so it can also be edited the same way as the JSON you propose.
  2. Use the k6 cloud test builder - needs just a (free) account, and you can export the test after that. Does not require you to install anything but k6 locally (well if you go with execution in the cloud, even that isn’t required)
  3. Use postman and then convert - this doesn’t support every postman feature, but probably non-technical people will not use anything that isn’t supported :wink: The community fork of the project has added a bunch of really nice features. There is also a video with Tim, the current maintainer, explaining how it’s used in their company and why they added all of those features and how they play together.
  4. probably some other converter from some other format to a k6 test. There are a bunch - some of them very out of date and abandoned - some less.

Otherwise, your code looks fine - it’s a good idea to use SharedArray as I expect this array can grow a lot. I am not certain the if in the POST is needed :person_shrugging: . Also in general post return 201 on success ;).

Hope this helps you !

2 Likes

Hey, @mstoykov Thanks a lot for the detailed replay, I really appreciate the time you invested in writing it.

I’ll take the time to investigate the options you’ve detailed.

I have a question regarding har format, I was looking at it before attempting my solution, but because it seems to be abandoned format and unmaintained I don’t feel it’s good practice to use it for a professional environment, which disappoints me because it looks exactly like the solution I was looking for.

It helps a lot, Thanks again!

I have a question regarding har format, I was looking at it before attempting my solution, but because it seems to be abandoned format and unmaintained I don’t feel it’s good practice to use it for a professional environment, which disappoints me because it looks exactly like the solution I was looking for.

I would mostly consider it complete for what it was intended :person_shrugging: .

Our frontend team has expanded on it for the needs of the test builder mentioned above and the har-to-k6 project does support that extended support. Arguably you can continue expanding it with your extensions if you need to :person_shrugging:

1 Like