Starting and running K6 programmatically?

Hi,
Is there any way to start and run the k6 programmatically? and also get the detailed report too?
I know I can execute the commands programmatically, but I was wondering is there any API or something like that available?

Hi @vahid4m and welcome to the forums! :partying_face:

There is currently no built-in support for this. With that said, it’s written in go and as we’ve not put the code in internal, you should be able to integrate with it if your application is written in go. With that said, it’s not really something I would recommend.

Would you mind explaining in more detail what you’re trying to do and what you look to achieve with it? I might be able to point you in some other direction that way.

Thanks,
Simme

Hi @simme
What I need is start the load generator form another machine using http requests and also get the output by this approach too. I think I’ll just write wrapper that executes the commands for this.

I also have another question which has nothing to do with this. But I’m asking it here.
Is there any way to store some variables for each response in a global object? I was thinking about using the cookie jar. So this is what I want:
in the default export function, for each request I get a response object. The object has some specific propriety in its header. I need to store that value for each response that I get and have access to them at the end of the test, or in the output json file or something like that.
Sorry for asking this in the middle of this thread.

Currently, we do not support writing data to files, or the output summary, from the default or teardown function. Further, it’s not possible to pass data from the default function to teardown. The reasoning behind this can be found here.

What you could do is to write this data to an external system using HTTP calls. However, if you do multiple iterations per VU, this will of course impact the performance of your test, and hence, I would not recommend it.