- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to set Multiple Tests for a Request in Postman with JavaScript Method?
We can set multiple Tests for a Request in Postman with JavaScript method. A Test in Postman gets executed only if a Request is successful. In case a Response does not get generated, a test does not to validate it.
Tests implemented in the JavaScript method are written within the Tests tab.
Add the following JavaScript verifications within the Tests tab −
tests["Status Code should be 200"] = responseCode.code === 200 tests["Response time lesser than 10ms"] = responseTime<10
The tests is a variable of type array which can hold data types- integer, string, Boolean and so on. The Status Code should be 200 and Response time lesser than 10ms are the test names. The responseCode.code is the code obtained in the Response and the responseTime captures the time taken to obtain the Response.
Select the GET method and enter an endpoint then click on Send.
Click on the Test Results tab in Response.
The Test Results tab displays the test which has passed in green and the test which has failed in red. The Test Results (1/2) means one out of the two tests has passed. Response shows the status as 200 OK and response time as 129ms (the second test checks if the response time is lesser than 10ms).
- Related Articles
- How to set Tests using Functional Method in Postman?
- How to set a Test in Postman with JavaScript Method?
- How to create a PUT request in Postman?
- How to create a DELETE request in Postman?
- How to create a POST request in Postman?
- How to set cookie value with AJAX request in JavaScript?
- How to see request logs in Postman console?
- How to use Global Variable in Postman Request?
- How to share Session ID Cookie with another request using Postman?
- Executing Tests on Cookies in Postman
- How to use JavaScript to set cookies for multiple pages?
- How to group selected tests from a set of tests in pytest?
- What is Pre-Request Script in Postman?
- How to set a global variable in Postman?
- How to set multiple cookies in JavaScript?
