Login API Automation


Features:

  • Supports for GET/POST/PUT/DELETE HTTP Methods
  • More simplified steps to do a API Test Automation.
  • Supports for data driven testing
  • Supports for multiple headers
  • Supports for path parameters
  • Supports for query parameters
  • Authorization can be configured from a step
  • Authorization token can be used among all the specifications

  1. Get a clone of IntelliAPI demo project from here
  2. As an example we’ll automate a login test
  3. Open “api_doc.xlsx” file inside resources/api_document
  4. Provide relevant details for “API_NAME”, “API_ENDPOINT”, “HTTP_METHOD”, “BODY_TYPE” and “JSON_PAYLOAD_TEMPLATE” columns as follows
Adding the entry in API document excel file

5. Save the excel file

6. Create a new specification in specs folder using any name

7. Now you can see the below spec file

Creating a spec file

8. You can give any name for Specification heading and Scenario heading

9. In the first step, you must define the API name which you need to invoke. That API name should be included in the “api_doc.xlsx” file

10. For this example I am going to use “Login” as the API name since I have provided those details in the excel file in step 4

11. Now you can write the first step as,

Preparing to invoke Login API
Preparing to invoke Login API

12. As the second step, you need to configure the authentication token. Since the login request doesn’t contain the token, we can provide configuration values as N/A

Setting authentication configurations
Setting authentication configurations

13. In the third step, you must create the JSON payload by replacing the values which was provided in the “api_doc.xlsx” file. Since my login payload contains the “username” and “password” properties and I have defined their values as “#username” and “#password” in the excel file, I will write the step as follows,

Setting the request attributes of the JSON payload
Setting the request attributes of the JSON payload

14. As the fourth step, I can invoke the API as follows,

Invoking the API
Invoking the API

15. Now I have invoked the API and I have the response as well. So I can validate the response using the following steps.

16. So in the fifth step, we’ll validate the status code of the response,

Validating the response status code
Validating the response status code

17. Then we’ll validate the response contents using JSON Path Assertions as follows,

Validating the response content using JSON path
Validating the response content using JSON path

18. Usually in the login response we can find the access token which will be used to authorize the next requests. So all we need to do is, save that token. It can be done as follows,

Saving the access token inside the response into a text file
Saving the access token inside the response into a text file

19. Now you have already completed the designing phase. You can execute this test scenario by clicking the green color play button on the left corner of the scenario heading

Executing the test scenario

20. After you run the test, go to reports/html-report and open “index.html”

21. You can see the test execution report as follows

Sample test execution report

That’s how this framework works. I will guide you to perform some other API test automation in coming tutorials.

Keep in touch……….


Happy Automation !!!

MaxSoft — IntelliAPI

Simple, Code-free and efficient framework for API Test Automation

Osanda Deshan Nimalarathna

Written by

Founder of MaxSoft | FOSS Contributor | Framework Developer | Senior Software Automation Engineer

MaxSoft — IntelliAPI

Simple, Code-free and efficient framework for API Test Automation

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade