API Automation
API automation testing is a type of automated software testing that validates the performance, functionality, reliability, and security of Application Programming Interfaces (APIs).
APIs act as intermediaries that allow different software applications to communicate with each other. Automated testing of these APIs ensures that they perform as expected, even under varying conditions such as high loads, incorrect inputs, or edge cases.
Rest-Assured: A Powerful API Automation Tool
Rest-Assured is a versatile Java-based library designed specifically for automating the testing of RESTful APIs. With its intuitive and expressive syntax, it simplifies the automation of API validations, making it an essential tool in API testing frameworks.
In API automation, Rest-Assured is typically integrated as a project dependency using Maven or Gradle.and enables developers to perform all API validations, such as checking HTTP response status, validating headers, and parsing JSON or XML payloads effortlessly.
Integrating TestNG for Robust Testing
By integrating TestNG, a versatile testing framework, the automation process is further organized and enhanced.
When combined with data-driven testing, where test data is stored in Excel sheets and dynamically loaded into test cases, the framework becomes scalable and highly maintainable.
TestNG, a powerful Java testing framework, provides a convenient way to implement data-driven testing by using the @DataProvider annotation.
The @DataProvider annotation is used to supply test data from external sources like arrays, Excel sheets, or databases. The data provider method returns an array of objects, where each object represents a set of test data.
Creating Rest Assured framework using TestNG Approach:
Step 1: Set Up Maven Project and add framework structure.Update pom.xml with required dependencies.
Create a new Maven project and add the necessary dependencies in your pom.xml file.
rest-assured
testng
testng.xml
json
json-path
json-schema-validator
scribejava-apis
lombok
poi
poi-ooxml
javafaker
json-schema-validator
maven-surefire-plugin
maven-compiler-plugin
maven-failsafe-plugin
log4j-api
log4j-core
allure-testng
extentreports

Framework structure:-

Step 2: Create an Excel file with test data under resources/testData folder
For example, POST_Create_userData_RA.xlsx with the following content:

Step 3: Create Config Properties src/test/resource
To set up endpoint URLs of user api
The config.properties file is a commonly used configuration file in API test automation projects, located in the src/test/resources directory. It stores essential environment-specific properties and test configurations in a key-value format, making it easy to manage and modify configurations without changing the code.

Step 4: Create user_endpoint java class for the userData
The UserEndpoint class implements CRUD (Create, Read, Update, Delete) operations for managing user data, utilizing Java's ResourceBundle for externalizing configuration values, such as the base API URL.
By using ResourceBundle, you centralize configuration management, making your framework flexible and maintainable.

Step 5: Create Pojo classes under api payloads package for Excel Data
Create separate POJO classes to map the Excel data for User data Request and Response.
For data-driven testing, Excel data is read and stored in POJO classes, simplifying access and manipulation.


Step 6: Create data driven test to Read Excel data under Utilities Package
It Includes dataproviders class and Excel utility class
@DataProvider annotation is used to supply test data from Excel sheets and allows the test to be executed for each data set provided by the DataProvider.


Step 7: Create Test Classes Using TestNG for each request type like for POST ,Delete, get etc.
These TestNG test classes to execute the tests using data from the Test data Excel file.
In these classes, we use ITestContext to store and share data across tests in the TestNG framework.
This approach facilitates API chaining, allowing all requests to be connected for end-to-end API testing. To achieve this, we set and retrieve values in ITestContext variables, enabling seamless data sharing between test methods.


Step 7: Create a TestNG XML suite to run the tests via TestNG XML.

Step 9: Generate reports as extent report ,allure reports
To generate Reports add necessary plugins in pom.xml
Step 10: Add logger file for logs

Step 11: Run the Tests from terminal.
Execute the tests by running the testng.xml suite file using the Maven Surefire Plugin from the terminal:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>

And execute following cmd:
mvn test -Dsurefire.suiteXmlFiles=testng.xml
This powerful combination of Rest-Assured, TestNG, and data-driven testing using @DataProvider annotation ensures comprehensive API coverage across various scenarios while simplifying the process of maintaining and expanding test cases.
Conclusion
Using Rest-Assured for API automation combined with TestNG's DataProvider feature provides a powerful and efficient framework for validating RESTful APIs. By leveraging DataProvider, testers can run data-driven tests effortlessly, ensuring broader scenario coverage and reducing code duplication.
This approach enhances test flexibility, allowing the use of multiple data sets to validate APIs against varied input conditions. The structured execution and robust reporting offered by TestNG further streamline the testing process, making it easier to maintain, debug, and scale the automation framework.
Adopting this combination ensures thorough validation of API functionality and performance, providing reliability and consistency essential for seamless system integration and end-user satisfaction.