Validation

Script

PruTAN lets you to add dynamic behaviour to REST requests. This allows you to write test suites and build requests that can contain dynamic parameters. You can add JavaScript code that executes at two events in the flow:

  • Validation are executed after a response is received from the server
  • You can add multiple functions/methods of validation to a request
  • You can add validation to both requests saved and not saved in a collection

PruTAN will then execute the script after the response is received.

Writing post-request validation

PruTAN ships a powerful API called xv which can handle post-request script as well as validation. Here we'll use xv to run validation on the response recieved from APIs.

Examples

Let us look at some examples of how you can use PruTAN to write validation.

Test response status code

Let us write a test to check whether the response to our request has a status code of 200. Which means that there are no errors in the response body.

Let's take the simulated request example used in Pre-Request Scripts :

https://dev-app.prutan.com/prutan/HB/4b26ddde-158c-4a77-92b2-df3507e88ede

In this case we'll need to write two expect statements one for checking the status and another for checking the request method. However we can wrap expect statements with the test method from the xv API to group related statements.

There are two ways to test the status code:

ConditionCode
Check if response code is 200xv.expect(xv.response.statusCode).toBe(200)
Check if request method is POSTxv.expect(xv.request.method).toBe("POST")

To validate request & response body values copy below scripts and use in Validation tab :

// Check status code is 200
xv.test("Status code is 200", ()=> {
    xv.expect(xv.response.statusCode).toBe(200);
});

 
// Check request property
xv.test("Check request property", ()=> {
    xv.expect(xv.request.method).toBe("POST");
});

Execute the simulated request with validation scripts to get following test result :

Script and the xv API

Read more about the xv APIs and it's documentation.