Validation
Welcome to PruTAN's Validation feature — a powerful testing framework that enables you to write automated tests to validate API responses after execution. With Validation, you can ensure your APIs are working correctly by checking response status codes and body content, making your API testing more robust and reliable.
Image 1 : Validation Tab
Overview
PruTAN's validation is post-validation of responses, executed after a response is received from the server. This allows you to write test suites that verify the correctness of your API responses.
Writing Validation Scripts
PruTAN provides a powerful validation object called pv (PruTAN Validator) for writing post-response validation scripts. These scripts use JavaScript syntax to test various aspects of the API response.
Common Validation Examples
Here are the main validation patterns available in PruTAN for REST APIs:
Status Code Validation
Purpose: Verify that the response status code matches expected values.
Example:
// Check status code is 200
pv.test("Status code is 200", res.validateResponse("200"));Response Body Property Assertion
Purpose: Assert specific property values from the response body.
Example: Sample response body:
{
"cartId": "CR230",
"message": "Added Successfully"
}Scripts:
// Check JSON response property value
pv.test("Check JSON response property value",
pv.expect(res.getBody("message")).toBe("Added Successfully"),
pv.expect(res.getBody("cartId")).toBe("CR230")
);Response Body Field Existence
Purpose: Check if specific fields exist or do not exist in the response body.
Examples:
// Check if field exists in response body
pv.test("Check response field exists", res.isFieldPresent("cartId"));
// Check if field does not exist in response body
pv.test("Check response field not exists", res.isFieldNotPresent("name"));Protocol-Specific Validation
Sample scripts for ISO & XML response bodies:
// Check ISO request & response property
pv.test("Check ISO request & response property", res.isValuePresent("3", "10200"));
// Check XML request & response property
pv.test("Check XML request & response property", res.isValuePresent("root.parent.hobby", "Chess"));Notes
- Test Results: Validations will be reported in the test results under response section
- Multiple Tests: You can add multiple validation tests to a single request
- Sample Templates: Sample templates are provided in the validation tab for reference. Users can click to add sample scripts to the validation tab editor for further customization
The Validation feature in PruTAN empowers teams to build comprehensive test suites — ensuring APIs perform as expected and catching issues early in the development process.