Yet, there are some features only available on k6, which is partially due to the fact that the Postman is catered for API testing or API functional testing, but k6 is focused more on API load testing. Both APIs are scriptable in JavaScript, and not everything is supported by both, due to the various browser and Node.js APIs used in the libraries. Some features needs external libraries, some are internal. ✅ (via k6 generator in openapi-generator)Īs you saw above, there are many features supported by each API, each to some extent. Selected libraries plus bundled ones (non-browser, non-Node.js APIs) Postman also supports javascript to do various tasks, but the focus is on exposing features via a richer set of GUI elements. Since k6 is scriptable from the start, you have the option to write the logic in JavaScript. To be fair, I have included features from Postman GUI application. Here's a quick comparison of the Postman API versus the k6 API. Then, I replaced the jsonData.hasOwnProperty syntax with the equivalent k6 syntax for extracting JSON response information: response.json("selector"). What adjustments did you make to the script to make it work?įirst, I removed the pre-script containing pm.sendRequest, because it is not supported by the converter. For a list of compatible libraries, please see jslib.k6.io.ģ. This can be fixed by importing bundled JavaScript modules. Since k6 uses Goja to run JavaScript, and it is not compatible with browsers' and Node.js APIs, hence there are some missing functionality. Is everything available out of the box in the converted script? If you convert from postman collections continuously, however, and run the script output as-is, it might make sense to keep it as is.Ģ. We recommend you to use the converter as an easy way to onboard and then rewrite your scripts to idiomatic k6 code, as we believe it to be more maintainable and less likely to degrade over time. If you expect to convert your collection continuously and without doing a lot of manual edits afterwards, yes. If you're using the converter as a way of onboarding, no. Should we base our load tests on the Postman converter and our Postman collections? When using your own collection, you should take all the steps to be able to have a k6 script out of your Postman collection, and to be able to run your load test with it.Ĭopy Remarks about using the postman-to-k6 converterġ️. This repository contains everything that is needed for load testing our test API, so you can skip to step 4. You can clone the repository and import the test-api.json and env.json files into the Postman application and possibly play with them if you want. I've created a repository for this article that contains the exported Postman collection, along with the converted script and related files. Optional: Clone the repository and skip to the step 5: In order to convert your Postman collection to k6 script, you should take the following steps:ġ. You can read more about its features in its release notes. We have created a tool that converts your Postman collection to k6 script, which is called postman-to-k6. Load Testing Our Test API with The Postman Collection This collection includes a set of collection variables, environment variables, pre-scripts, tests, authorization with two different mechanisms, and usages of the Postman Sandbox API. You'll see how you can access this Postman collection shortly. To ease testing of our test API and demonstrate the usage of our Postman to k6 converter, I've created a Postman collection with almost all of our test API requests. The order is very important in the private APIs, since you cannot delete a non-existing resource, for example. The extracted token is used to make other API calls. For the private APIs, a user is created and its token is extracted. The scenario is to test all the public and private APIs. Update selected fields on your crocodile.These endpoints are available in the Postman collection: In order to demonstrate the power of k6 in different scenarios, we have created our test API with various example endpoints, which is available at test-api.k6.io. Copy In-depth guide Our Test API & Its Testing Scenario
0 Comments
Leave a Reply. |