📡

Creating an API Test Automation Framework

Mar 15, 2025

Building an API Test Automation Framework from Scratch

Introduction

  • The lecture is about building a complete API test automation framework from scratch using the Rest Assured library.
  • Conducted by Jutan, Principal QA with 10+ years of experience in automation testing and DevOps.
  • Part of the Live Sessions from the SAD Mastery Program.

Key Learning Objectives

  • How to create an API test automation framework from scratch.
  • Use of Rest Assured library in the framework.
  • Understanding and applying different design patterns in API testing.
  • Writing clean and maintainable test scripts.
  • Addressing common challenges faced by students and professionals.
  • Observing live coding for building the framework.

Course Notes and Resources

  • Notes for the entire course are available in the description section of the video.

Live Class Details

  • Interactive group session with discussions and Q&A.
  • Focused on building an API automation framework over two days.
  • Participants are expected to solve assignments and interview questions available on the LMS.

Framework Building Steps

Day 1: Introduction and Framework Setup

  1. Framework Planning

    • Review the Swagger document for understanding API endpoints.
    • Identify services and endpoints for automation.
    • Create a Maven-based project in Java.
    • Set Java version to 11.
    • Add dependencies for Rest Assured and TestNG in pom.xml.
  2. Base Service Class Creation

    • Responsible for handling base URI, IP address, creating request specifications, and handling responses.
    • Acts as a wrapper for Rest Assured.
  3. Service Object Model

    • Create service classes for each API service (e.g., Authentication Service).
    • Each service class contains relevant methods.
    • Implement Base Service for common functionalities across services.
  4. Writing Test Scripts

    • Use TestNG for structuring tests.
    • Implement method chaining for cleaner code.
    • Use Static Import for readability.
  5. Serialization and Deserialization

    • Use Jackson library for object mapping (JSON to Java objects and vice versa).
    • Create request and response models (POJOs).

Day 2: Advanced Implementation

  1. Builder Design Pattern

    • Implement to handle complex payloads with ease.
    • Allows setting fields in any order without remembering parameter positions.
  2. Handling Authorization and Tokens

    • Manage authorization tokens for secure API access.
    • Enhance Base Service to handle token settings.
  3. Loggers and Listeners

    • Integrate Log4j for logging test execution details.
    • Implement TestNG Listeners for tracking test execution: start, success, failure, and finish events.
  4. Implementing Filters

    • Use filters for intercepting API requests and responses.
    • Capture and log request/response details for debugging and analysis.
  5. Running Tests from Terminal

    • Configure Maven Surefire Plugin for command-line test execution.
    • Create TestNG XML suite for structured test runs.

Day 3: CI/CD Integration

  1. GitHub Actions Setup

    • Integrate with GitHub Actions for CI/CD pipeline.
    • Configure workflows for automatic test execution.
  2. Logging and Reporting

    • Capture detailed logs including request and response data.
    • Generate and publish reports on test outcomes.
  3. Enhancements and Best Practices

    • Implement method chaining for better readability.
    • Discuss enhancements like security testing, database connectivity, and more.

Conclusion

  • The course provides a comprehensive guide to building and running an API test automation framework.
  • Emphasizes practical implementation and real-world applications.
  • Encourages solving assignments and applying learned concepts in office projects and interviews.