
- #CODE SNIPPET SAVER CODE#
- #CODE SNIPPET SAVER SERIES#
Click on ‘Add’ and set the environment name as ‘Test’. To add an environment click on ‘No environment’ on the top right corner of the screen. This way you can easily switch between different servers without changing your requests. Working with variables (Environment and global)Įnvironments- give you the ability to customize requests using variables. This test checks if the errorCode is: “ TAR_ERR400_06” Var data = JSON.parse(responseBody) tests = jsondata.errorCode = “ TAR_ERR400_06” In case you are trying to login with invalid credentials, the test below will check if the ‘errorCode’ in the response is correct. Var jsonData = JSON.parse(responseBody) tests = jsonData.value = 100 Snippet- ‘Response body: JSON value check’. This test snippet will check the response for the string “ Invalid credentials.” Tests =responseBody.has(“ Invalid credentials. “) #CODE SNIPPET SAVER CODE#
You can use this simple code to check for a string in the response. In case you are running a test that is attempting to log in with invalid credentials, assume that you will get a response like the one below. Tests =responseBody.has(“ string_you_want_to_check“)
Snippet- ‘Response body: Contains string’. For a scenario like uploading a large file you can edit this snippet as follows: This simple snippet checks if the response time was less than 200ms.
Snippet- ‘Response time is less than 200ms’. For scenarios as logging in with invalid credentials you can assign the response to 400(Bad request). You can use the snippet as is, with most positive scenarios. This is the most basic snippet which checks if the response code is 200(The request has succeeded). This will generate a code template and you can modify it based on your context. You can select a snippet that is on the right panel as shown below. To begin writing a test, first click on the ‘ Tests’ tab under Postman ’Builder’ tab. This provides an early evaluation of its overall build strength before running GUI tests. The major advantage of API automation is that we can access the application without a user interface. API automated tests are far less time consuming than UI automated tests. Postman drastically reduces the pressure of regression testing from the QA team. Postman is a real time saver making it easier for developers to develop and test APIs. Writing tests in Postman is made easy by JavaScript and inbuilt snippets, allowing any inexperienced tester to write an efficient test. These tests will validate every single time if the response is correct. Moreover, the learning curve for using it is very low and the app provides a very clean and intuitive user interface to test your server requests. The main reason I like Postman is because of its powerful automation capabilities. In this article, I would like to give a quick overview of the test snippets provided by Postman. They are unaware of the powerful features that postman offers like: Collections, Tests and Pre-request scripts. However, many use it just to check the response for the services that they are working on.
It helps to automate the process of making API requests and testing API responses, allowing testers to establish a very efficient workflow. Most programmers and testers are familiar with Postman.
Postman is a Google Chrome app that helps you to create, save, send HTTP requests and test the response data. This post will look at how these API code snippets can help your API testing. The first post looked at what is API testing.
#CODE SNIPPET SAVER SERIES#
This is the second part of a two part series on API testing.