Examples
Expect an error
A workflow that logs in with a wrong password and passes only if the API answers 400, and the same check as a rejection case.
What it tests: a login with a wrong password must be rejected with a 400 and the message Invalid credentials.
Open it in Luvin
Section titled “Open it in Luvin”- Download the files with the buttons above.
- In Luvin, create a collection with New collection on the workspace home, or open one you already have.
- Under Quick actions, click Import Arazzo or contracts and choose the downloaded
.yamlfiles together. - In the sidebar, open the workflow Wrong password.
- In the run bar, choose Real API.
- Press Run. The results open at the bottom.
The key lines
Section titled “The key lines”arazzo: 1.0.1info: title: The API rejects a wrong password version: 1.0.0sourceDescriptions: - name: dummyjson url: ./dummyjson.openapi.yaml type: openapiworkflows: - workflowId: wrongPassword summary: Log in with a wrong password and expect the 400 inputs: type: object required: [username, password] properties: username: { type: string, example: emilys } password: { type: string, example: not-the-password } steps: - stepId: loginRejected operationId: login requestBody: contentType: application/json payload: username: $inputs.username password: $inputs.password successCriteria: - condition: $statusCode == 400 - condition: $response.body#/message == 'Invalid credentials' outputs: message: $response.body#/message outputs: message: $steps.loginRejected.outputs.message| Line | What it does |
|---|---|
| 27 | $statusCode == 400: the step passes only if the API answers 400. A 200 here would fail it. |
| 28 | The body must carry the documented message, Invalid credentials. Text is compared without distinguishing capitals. |
| 24-25 | The username and password come from the inputs. The default password in the file is not-the-password, which is wrong on purpose. |
What you get
Section titled “What you get”The API answers 400 with {"message":"Invalid credentials"}. The step counts as successful because that is the answer the criteria ask for.
| Step | HTTP status | Output |
|---|---|---|
loginRejected |
400 | message = Invalid credentials |
Verdict of the workflow: Passed. The workflow output message is Invalid credentials.
If you change the password to emilyspass, the API logs you in and answers 200. The step then fails with the reason Expected $statusCode equal to 400, but it is 200.
The same check as a rejection case
Section titled “The same check as a rejection case”You can also leave a workflow written for success, such as the login of Log in and use the token, and test the rejection from the Cases tab.
- Open the workflow and click the Cases tab.
- In the group Custom data cases, press + New data case.
- In Case name, type
Wrong password. In Step to check, chooselogin. - In Expected status, type
400. - Under Case inputs, type
not-the-passwordinpassword. - Press Add case, then Run with Real API.
The case ends as Passed. The step login shows Responded 400 (expected) and the note This is what the case tests, because here the error is what the case wants.
Try this
Section titled “Try this”- Change
passwordtoemilyspassand run again. The workflow ends Failed with Expected $statusCode equal to 400, but it is 200. That is how you notice that the API stopped rejecting. - Remove line 28 and keep only the status. The step passes on any 400, with whatever message.