REST API TEST AUTOMATION

API Test Automation

This repository is created to handle API testing in efficient manner. Primary reason to develop this framework was to minimize and speed up the testing activities that BA's are doing at the moment. This framework is written in such a way that it can be used to test any API endpoints without any code change.

Prerequisite

This framework is written in python language and used pytest to write test methods. Need Python 3+ to execute test in this framework. Other required prerequisite's are mentioned in dependencies/requirements.txt file

How to use it :

The required dependencies are mentioned in dependencies/requirements.txt file and configuration related information are in configuration/config.txt This framework needs a CSV input that comprise of API details, the CSV headers are as follows:

TESTCASE_ID : Field to add test case id , e.g. TC-01. Please add '_' if its a chained API e.g. : TC-02_01

DESCRIPTION : Field to add test case description

HTTP_METHOD : This is for

URI : This is the uri for endpoints, values can be {host}/getUser/user1 where host is mentioned in configuration/config.txt file as a key value pair

REQUEST_HEADER : Request header for the API if any

REQUEST_BODY : Request body if any , Prefix '#' if there are any dependent values from the previous request e.g. : "#{"name":"test_name","job":"$.test_job"}" here '$.test_job' is the JSON Path for the value from the previous request

RESPONSE_CODE : Provide expected response code for validation purpose

MAX_TIMEOUT : Provide max timeout in seconds if any. By default max_timeout will have value mentioned in config file

RESPONSE_HEADER : Provide expected header for validation

RESPONSE_BODY : Expected response body for validation purpose

JSON_SCHEMA_VALIDATION : Provide value as TRUE/YES if the json response needs to be validated against json response schema; for any other value, schema validation is skipped

JSON_SCHEMA_PATH : Mandatory if the value supplied for csv header JSON_SCHEMA_VALIDATION is TRUE/YES. Value should be the relative path of expected json response schema file {json schema can be easily generated by websites like https://jsonschema.net/; refer file json_schema/response/get_en_v1_currencies.json in the project}

IGNORE_FIELD_VALIDATION : Optional header with value containing the list of json fields/keys to be ignored from json response assertions; can contain one or more keys separated by comma {e.g., "id, firstName, lastName"}

TAKE_VALUE : take_value and take_from values are used for chained APIs, provide the json path to get the values e.g. : $.test_job

TAKE_FROM : From where to take the value for take_value, values can be from RESPONSE_BODY

DB_CLEANUP : Optional, Provide JSON for DB cleanup if any for the current test case

DB_VERIFY : Optional, Provide JSON for DB verify if any for the current test case

How to run the tests

Run this command from project root directory : python3 -m pytest tests/test_input.py --tb=no -s --html=api_test_results.html --self-contained-html where test_input.py is the test class api_test_results.html is the resultant html report, can be found in root directory after the test execution
Apart from the api_test_results.html file we do capture all the request header/body and response header/body in a separate folder structure, that can be found in 'test_output' folder after the execution

Useful websites:

http://jsonviewer.stack.hu/ : This site is helpful to arrange json inputs to single line, remove space, beautify etc https://jsonschema.net/ : This site is helpful to create json schema from json response

Confluence:
https://29022131.atlassian.net/wiki/spaces/ECI/pages/1094385856/Test+Automation+for+Data-Pipeline

CSV Template:
https://docs.google.com/spreadsheets/d/1RJmD9abX2GUoJ0X8g6MJQQ0honE31zni3ixrsntZB7o/edit?ts=5da40f88#gid=806711360

NEW FEATURE:

https://docs.google.com/document/d/1yqgerva_YyEj4jFW8wVK0Dd2zRr5FKLforZfk-y9iZg/edit?usp=sharing