- getting started
- Get Started with Automating Web Applications
- Get Started with Automating Mobile Web Applications
- Get Started with Automating Android Apps
- Get Started with Automating iOS Apps
- Get Started with REST API Testing
- test cases
- web apps
- How to create web application tests using Test Recorder
- How to create Test Steps for uploading files
- mobile apps
- How to create Android & iOS app tests using Test Recorder
- How to automate Android app tests using local devices
- How to automate iOS app tests using local devices
- How to automate data driven testing
- REST API
- What is JSONPath and How to query JSON using JSONPath
- Contract Testing with Testsigma
- Consumer Driven Contract Testing with Testsigma
- test plans
- How to create test plans to run on your local devices
- How to do cross-platform end-to-end testing with Testsigma
Get Started with REST API Testing
In this tutorial, we will demonstrate how RESTful APIs or web services can be tested using Testsigma. In this demo, we are going to use JSONPlaceholder which is a free online REST service that you can use whenever you need some mock data.
API resources and routes
Resources
API Entry point - https://jsonplaceholder.typicode.com/
These are the resources or mock data available for inspection via the API. The left column specifies the URL for the request and right column specifies the number of JSON object items returned in the response.
/posts | 100 items |
/comments | 500 items |
/albums | 100 items |
/photos | 5000 items |
/todos | 200 items |
/users | 10 items |
We can append any of the above resource names to the API entry point to form a valid GET request.
Routes
A few of the available routes are given below:
https://jsonplaceholder.typicode.com/posts | will return a response containing 100 posts |
https://jsonplaceholder.typicode.com/posts?userId=1 | will return a response containing the posts for userid=1 |
https://jsonplaceholder.typicode.com/posts/1 | will return a response containing the post with id=1 |
https://jsonplaceholder.typicode.com/posts/1/comments | will return a response containing the comments for post with id=1 |
https://jsonplaceholder.typicode.com/comments | will return a response containing 500 comment items |
https://jsonplaceholder.typicode.com/comments?postId=1 | will return a response containing the comments for post with id=1 |
https://jsonplaceholder.typicode.com/users | will return a response containing 10 users |
https://jsonplaceholder.typicode.com/users/1 | will return a response containing the user details for id=1 |
All of the most common HTTP verbs such as GET, POST, PUT, PATCH, and DELETE are supported.
If you are new to Web Service Testing, see How to add Test Steps for Web Service/API Testing.
Demo Test
Now, let us test the above API using Testsigma. We will perform a total of 8 tests as given below:
- Test the Expected Response Status Code for a simple GET request.
- Test the Expected Response Header for a GET request.
- Test the Expected Response Body for a GET request.
- Create a user using POST request and test the Expected Status Code, Header, and Body.
- Create a user using PUT request and test the Expected Status Code, Header, and Body.
- Delete a user using DELETE request and test the Expected Response.
1. Test the Expected Response Status Code for a GET request
This test checks for the Expected Status Code of the Response for a simple GET request (no request header provided). The following entries are to be made in Testsigma:
URL: https://jsonplaceholder.typicode.com/users
HTTP Method: GET
Test: Status Code
Expected Status Code: 200
2. Test the Expected Response Header for a GET request
This test checks for the Expected Header of the Response for a simple GET request (no request header provided). The following entries are to be made in Testsigma:
URL: https://jsonplaceholder.typicode.com/users
HTTP Method: GET
Test: Header Test
Expected Header Content: {"content-type":"application/json; charset=utf-8"}
3. Test the Expected Response Body for a GET request
This test checks for the Expected Body Content of the Response for a simple GET request (no request header provided). The following entries are to be made in Testsigma:
URL: https://jsonplaceholder.typicode.com/users/1
HTTP Method: GET
Test: Validate User data
Expected Body Content: {"id": 1,"name": "Leanne Graham","username": "Bret","email": "Sincere@april.biz"}
Body Comparison Type: Lenient
4. Create a post using POST request and test the Expected Status Code, Header, and Body
This test creates a post using POST request and checks for the Header, Body and Status Code of Expected Response with no request header. The following entries are to be made in Testsigma:
URL: https://jsonplaceholder.typicode.com/posts
HTTP Method: POST
Payload: {"title":"foo","body":"bar","userId":1}
Expected Status Code: 201
Expected Header: {"content-type":"application/json; charset=utf-8"}
Expected Body: {"id":101,"title":"foo","body":"bar","userId":1}
Comparison Type: Lenient
5. Update a post using PUT request and test the Expected Status Code, Header, and Body
This test updates a post using PUT request and checks for the Header, Body and Status Code of Expected Response with no request header. The following entries are to be made in Testsigma:
URL: https://jsonplaceholder.typicode.com/posts
HTTP Method: PUT
Payload: {"title":"foo","body":"bar","userId":1}
Expected Status Code: 200(updated)
Expected Header: {"content-type":"application/json; charset=utf-8"}
Comparison Type: Lenient
Expected Body: {"id":101,"title":"foo","body":"bar","userId":1}
Comparison Type: Lenient
6. Delete a user using DELETE request and test the Expected Response
This test deletes a user and checks the Expected Header Response for a simple DELETE request with no request header. The following entries are to be made in Testsigma:
URL: https://jsonplaceholder.typicode.com/users/1
HTTP Method: DELETE
Test: Status Code
Expected Status Code: 200
Expected Header: {"content-type":"application/json; charset=utf-8"}
Comparison Type: Lenient