Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

Could k6 check be added into the generated script? #61

Closed
liangway opened this issue Jun 10, 2020 · 1 comment
Closed

Could k6 check be added into the generated script? #61

liangway opened this issue Jun 10, 2020 · 1 comment

Comments

@liangway
Copy link

Thanks a lot for implementing this tool, it's very easy to have k6 test script from postman.
And I have a noob question.

Could we add k6 checks to the generated script? And how?

@simskij
Copy link
Contributor

simskij commented Jun 11, 2020

Hi!

Sure, just edit the output file adding the check you want! While this is indeed possible, we do recommend most users to rewrite the parts of their output that they want to modify using more k6 idiomatic code, as shown in the docs you refer to. In that case, you would have to replace the postman[Request] part to instead use the HTTP client directly.

For instance, given that you have a request that looks like this in your output:

    postman[Request]({
      name: "Get page",
      id: "4c08d3d5-93d8-4c78-a6d2-212e3fcf2404",
      method: "GET",
      address: "https://test-api.k6.io/",
      data: {},
    });

you may add the post property to that object to do assertions post the request being executed:

    postman[Request]({
      name: "Get page",
      id: "4c08d3d5-93d8-4c78-a6d2-212e3fcf2404",
      method: "GET",
      address: "https://test-api.k6.io/",
+     post(response) {
+       tests["Status code is 200"] = responseCode.code === 200;
+     }
    });

Hope that helps,
Simme

@simskij simskij closed this as completed Jun 11, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants