Skip to content

coderboy132451/API-Test-Automation-Task-

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

<<<<<<< HEAD

API-Test-Automation-Task-

API Test Automation Task using Java + Rest Assured

API Test Automation - ReqRes

This project contains automated tests for the ReqRes API using Java, Rest Assured, and TestNG.

Project Structure

API Test Automation/
├── src/
│   ├── main/java/com/apitest/
│   │   └── utils/
│   │       ├── APIConfig.java       (API configuration and constants)
│   │       └── APIClient.java       (HTTP client wrapper)
│   └── test/java/com/apitest/
│       ├── tests/
│       │   └── UserAPITest.java     (Test cases)
│       └── models/
│           ├── User.java            (User model)
│           └── UserResponse.java    (Response wrapper)
├── pom.xml                          (Maven configuration)
├── testng.xml                       (TestNG suite configuration)
└── README.md                        (This file)

Prerequisites

Test Scenarios

Test Case 1: Create User

  • Endpoint: POST /api/users
  • Validates:
    • HTTP Status Code = 201 (Created)
    • User ID is generated and stored
    • Response contains created user details (name, job, timestamp)

Test Case 2: Get User Details

  • Endpoint: GET /api/users/{userId}
  • Validates:
    • HTTP Status Code = 200 (OK)
    • Retrieved user details match created user
    • User ID, name, and job are correct

Test Case 3: Update User

  • Endpoint: PUT /api/users/{userId}
  • Validates:
    • HTTP Status Code = 200 (OK)
    • User name is updated correctly
    • User job is updated correctly
    • User ID remains unchanged
    • Updated timestamp is present

Running Tests

Run all tests

mvn test

Run specific test class

mvn test -Dtest=UserAPITest

Run with detailed output

mvn test -X

Run using TestNG directly

mvn surefire:test

Test Output Example

============ Test 1: Create User ============
Response Status: 201
Response Body: {"name":"Automation Tester","job":"QA Engineer","id":123,"createdAt":"2026-05-20T10:30:00.000Z"}
✓ User created successfully with ID: 123
✓ Status Code validation: PASSED

============ Test 2: Get User Details ============
Response Status: 200
✓ User details retrieved successfully
✓ User ID validation: PASSED
✓ User name validation: PASSED
✓ User job validation: PASSED

============ Test 3: Update User Details ============
Response Status: 200
✓ User updated successfully
✓ Name updated from 'Automation Tester' to 'Updated Automation Tester'
✓ Job updated from 'QA Engineer' to 'Senior QA Engineer'
✓ All validations: PASSED

Key Dependencies

  • Rest Assured 5.3.2: RESTful API testing library
  • TestNG 7.8.1: Testing framework
  • Gson 2.10.1: JSON serialization/deserialization
  • Lombok 1.18.30: Reduces boilerplate code

Configuration

API endpoints and constants can be modified in APIConfig.java:

public static final String BASE_URL = "https://reqres.in";
public static final String DEFAULT_USER_NAME = "Automation Tester";
public static final String DEFAULT_USER_JOB = "QA Engineer";

Test Execution Flow

┌─────────────────────────────────────┐
│ Test 1: Create User                 │
│ ✓ POST /api/users                   │
│ ✓ Validate Status 201               │
│ ✓ Store User ID                     │
└──────────────┬──────────────────────┘
               │ (Pass)
┌──────────────▼──────────────────────┐
│ Test 2: Get User Details            │
│ ✓ GET /api/users/{userId}           │
│ ✓ Validate Status 200               │
│ ✓ Verify User Data                  │
└──────────────┬──────────────────────┘
               │ (Pass)
┌──────────────▼──────────────────────┐
│ Test 3: Update User                 │
│ ✓ PUT /api/users/{userId}           │
│ ✓ Validate Status 200               │
│ ✓ Verify Updated Data               │
└─────────────────────────────────────┘

Assertions Used

  • assertEquals(): Validate exact values (status codes, strings)
  • assertNotNull(): Verify response fields are populated
  • assertTrue()/assertFalse(): Validate boolean conditions

Notes

  • Tests are dependent on each other using dependsOnMethods in TestNG
  • User ID from Test 1 is used in Tests 2 and 3
  • Each test prints detailed output for debugging purposes
  • Assertions provide clear failure messages with expected vs actual values

Troubleshooting

Build Issues

mvn clean install

Dependency Issues

mvn dependency:tree

Test Failures

  • Check internet connection
  • Verify https://reqres.in/ is accessible
  • Check logs for detailed error messages

Next Steps

Extend this framework by adding:

  • Configuration file support (.properties, .yaml)
  • Parameterized tests with data providers
  • Additional endpoints (List users, Delete user, etc.)
  • Custom assertions and utilities
  • Test reporting (Allure, ExtentReports)
  • CI/CD integration (Jenkins, GitHub Actions)

b419ba1 (Initial commit: API Test Automation upgrade + product tests)

About

API Test Automation Task using Java + Rest Assured

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages