![]() 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. For cookies, a dict in the cookies parameter.įor more information about how to pass data to the backend (using httpx or the TestClient) check the HTTPX documentation.Copy In-depth guide Our Test API & Its Testing Scenario.To pass headers, use a dict in the headers parameter.If you need to send Form Data instead of JSON, use the data parameter instead.To pass a JSON body, pass a Python object (e.g.To pass a path or query parameter, add it to the URL itself.Whenever you need the client to pass information in the request and you don't know how to, you can search (Google) how to do it in httpx, or even how to do it with requests, as HTTPX's design is based on Requests' design. From typing import Annotated from fastapi import FastAPI, Header, HTTPException from pydantic import BaseModel fake_secret_token = "coneofsilence" fake_db =
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |