Validating Postscript
Validating postscript values
Last updated
Validating postscript values
Last updated
Most scenarios with postscript require you to validate specific values to ensure a successful API test flow. Loadmill provides 2 methods in validating postscript values: Using Mocha or Assertions.
Mocha is a JavaScript test framework making asynchronous testing very simple. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases.
In the previous article we showed how to verify if a value exists in an array or API response. In our example we tested with a fruits API that returns a list of fruits with their properties and verified if a specific fruit was part of that list.
In order to validate the API based on the value of orangeOnList we would add the following line of code:
Furthermore, a validation error would result the test to fail providing a comprehensive error message:
You can reference yourself with the Mocha documentation for more useful functions to better test your API flows at https://mochajs.org/
Another way to validate a value from postscript is via the Assertion section of the API container. Once your value is saved in a variable, you can use that variable for validation.
Make sure to convert any variable to a string type while using the Assertion section.
In this case our code should look like the following:
This now converts the boolean value true
to a string type.
To validate your API based on orangeOnList:
Add an Assertion.
Select/type isOrangeOnList on the parameters list.
Select “Equals” from the Values dropdown.
Type true
on the field.
Run your API test.