Examples
Send generated data
Build a request body with generators such as a random name and email, and check what the API echoes back.
Tests that reuse the same test user collide or go stale. Generators make Luvin write a new value every time the request is sent.
What it tests: that a body built from generators and inputs is accepted (201) and that the API echoes the data you sent.
Download the files
Section titled “Download the files”Open it in Luvin
Section titled “Open it in Luvin”- Download the two files above into one folder.
- In Luvin, press New collection, or open a collection you already have.
- On the collection home, press Import Arazzo or contracts and pick both downloaded files.
- In the sidebar, open the workflow
addGeneratedUser. - In the run bar, choose Real API.
- Press Run. The results open at the bottom.
The Arazzo file
Section titled “The Arazzo file”arazzo: 1.0.1info: title: Create a user with generated data version: 1.0.0sourceDescriptions: - name: dummyjson url: ./dummyjson.openapi.yaml type: openapiworkflows: - workflowId: addGeneratedUser summary: Send a new random user on every run and check the echo inputs: type: object properties: age: { type: integer, example: 29 } steps: - stepId: addUser operationId: addUser requestBody: contentType: application/json payload: firstName: '{{$randomFirstName}}' lastName: '{{$randomLastName}}' email: '{{$randomEmail}}' age: $inputs.age successCriteria: - condition: $statusCode == 201 - condition: $response.body#/age == $inputs.age - context: $response.body#/email condition: ^[^@\s{]+@[^@\s]+\.[^@\s]+$ type: regex - context: $response.body#/firstName condition: ^[^{]+$ type: regex outputs: id: $response.body#/id firstName: $response.body#/firstName email: $response.body#/email outputs: firstName: $steps.addUser.outputs.firstName email: $steps.addUser.outputs.email| Line | What it does |
|---|---|
'{{$randomFirstName}}' (22) |
Luvin replaces the generator with a made-up first name when it sends the request. Write it in quotes in YAML. |
'{{$randomLastName}}', '{{$randomEmail}}' (23-24) |
Each one is a new value. They are independent of each other. |
age: $inputs.age (25) |
A normal input, mixed with the generators in the same body. |
$response.body#/age == $inputs.age (28) |
The echoed age must equal the one sent. |
type: regex on email (29-31) |
The echoed email must look like an address and must not still contain a {, the sign of an unresolved generator. |
type: regex on firstName (32-34) |
The echoed first name must not contain a { either. |
What you get
Section titled “What you get”| Step | HTTP status | Outputs |
|---|---|---|
addUser |
201 | id (assigned by the API), firstName, email (the echoed generated values) |
The verdict is Passed. The outputs differ on every run. Two runs of this recipe sent, for example, Joyce with Lavern.Leannon@gmail.com and Amiya with Valentina_Hodkiewicz77@hotmail.com.
The generators of Luvin follow the names of Postman ({{$guid}}, {{$randomInt}}, {{$randomCity}} and more). Names come out in the language of the interface: with Luvin in Spanish, {{$randomFirstName}} produces Spanish-speaking names. See Dynamic variables for the full list.
Try this
Section titled “Try this”- Run it twice. Press Run again and open the step:
firstNameandemailare different. No input changed. - Change an input. Set
ageto41. The body sends 41, the API echoes 41 and the criterion onagestill passes.