Modern API automation framework using Karate Framework 1.4.1 with Page Object Model (POM) pattern for testing automation exercise APIs. Features comprehensive test coverage, multiple execution strategies, and detailed HTML reporting.
- β Karate Framework 1.4.1 with GraalVM JavaScript engine support
- β Page Object Model (POM) pattern for maintainable test structure
- β Multiple Test Runners for different execution scenarios
- β Tag-based Test Execution for targeted testing
- β Comprehensive API Validation (status, structure, data types)
- β Negative Testing for error scenario coverage
- β Rich HTML Reports with detailed request/response logs
- β JUnit 5 Integration for modern testing framework
- β Environment Configuration support
karateFramework-API-automation/
βββ src/
β βββ test/
β βββ java/
β βββ api/
β β βββ products/
β β β βββ ProductsApi.feature # Products API test scenarios
β β βββ brands/
β β β βββ BrandsApi.feature # Brands API test scenarios
β β βββ runners/
β β β βββ ApiTestRunner.java # All API tests runner
β β β βββ SmokeTestRunner.java # Smoke tests runner
β β β βββ RegressionTestRunner.java # Regression tests runner
β β β βββ SimpleKarateRunner.java # Direct execution runner
β β βββ utils/
β β β βββ common-utils.js # Utility functions
β β βββ data/
β β βββ README.md # Test data documentation
β βββ karate-config.js # Global configuration
βββ target/
β βββ karate-reports/ # Generated test reports
βββ pom.xml # Maven configuration
βββ README.md # This file
- Endpoint:
https://automationexercise.com/api/productsList
- Method:
GET
- Description: Retrieves complete products catalog with details
- Expected Response:
200 OK
with JSON array of products - Test Coverage: Success scenarios, data validation, negative testing
{
"responseCode": 200,
"products": [
{
"id": 1,
"name": "Blue Top",
"price": "Rs. 500",
"brand": "Polo",
"category": {
"usertype": {"usertype": "Women"},
"category": "Tops"
}
}
]
}
- Endpoint:
https://automationexercise.com/api/brandsList
- Method:
GET
- Description: Retrieves all available brands information
- Expected Response:
200 OK
with JSON array of brands - Test Coverage: Success scenarios, data validation, negative testing
{
"responseCode": 200,
"brands": [
{
"id": 1,
"brand": "Polo"
}
]
}
Tag | Purpose | Description |
---|---|---|
@smoke |
Critical Tests | Essential scenarios for basic functionality |
@regression |
Full Coverage | Comprehensive test suite for all features |
@negative |
Error Testing | Invalid inputs and error scenario validation |
@products |
Products API | All test scenarios related to products endpoint |
@brands |
Brands API | All test scenarios related to brands endpoint |
- βοΈ Java 11+ - Required for Karate 1.4.1
- βοΈ Maven 3.6+ - Build and dependency management
- βοΈ IDE (IntelliJ IDEA, VS Code, Eclipse) - For development
-
Clone the repository
git clone https://github.com/adityadwic/karateFramework-API-automation.git cd karateFramework-API-automation
-
Install dependencies
mvn clean compile test-compile
-
Verify setup
mvn test
mvn test
# Run smoke tests only (critical scenarios)
mvn test -Dtest=SmokeTestRunner
# Run regression tests only (full coverage)
mvn test -Dtest=RegressionTestRunner
# Run all API tests (comprehensive)
mvn test -Dtest=ApiTestRunner
# Run smoke tests
mvn test -Dkarate.options="--tags @smoke"
# Run regression tests
mvn test -Dkarate.options="--tags @regression"
# Run negative tests only
mvn test -Dkarate.options="--tags @negative"
# Run product tests only
mvn test -Dkarate.options="--tags @products"
# Run brand tests only
mvn test -Dkarate.options="--tags @brands"
# Exclude specific tags
mvn test -Dkarate.options="--tags ~@ignore"
Run tests directly using the SimpleKarateRunner:
# Compile first
mvn clean compile test-compile
# Run with Java (includes classpath dependencies)
mvn exec:java -Dexec.mainClass="api.runners.SimpleKarateRunner"
- IntelliJ IDEA: Right-click on any runner class β Run
- VS Code: Use Java Test Runner extension
- Eclipse: Right-click on runner β Run As β JUnit Test
Tests provide real-time feedback with emojis and color coding:
π Running Karate API Tests...
β
Smoke Tests Results:
Features Total: 2, Features Passed: 2, Features Failed: 0
Scenarios Total: 6, Scenarios Passed: 6, Scenarios Failed: 0
π All tests passed! Karate Framework is working perfectly!
After execution, detailed reports are generated in:
target/karate-reports/
βββ karate-summary.html # Main report dashboard
βββ api.products.ProductsApi.html # Products API detailed report
βββ api.brands.BrandsApi.html # Brands API detailed report
βββ *.karate-json.txt # Raw JSON results
Open karate-summary.html
in your browser for:
- π Test execution statistics
- π Request/Response details
- β±οΈ Performance metrics
- π Failure analysis
- π Step-by-step execution logs
Base URL and global settings are configured in karate-config.js
:
function fn() {
var config = {
baseUrl: 'https://automationexercise.com/api',
timeout: 30000,
env: 'dev'
};
karate.log('Environment:', config.env);
return config;
}
Key dependencies and versions in pom.xml
:
<properties>
<karate.version>1.4.1</karate.version>
<junit.version>5.9.3</junit.version>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
-
Page Object Model (POM)
- Separates test logic from test data
- Improves code reusability and maintainability
- Organized feature files by API endpoints
-
Tag-Based Execution
- Flexible test execution strategies
- Easy integration with CI/CD pipelines
- Selective test running capability
-
Multiple Test Runners
- ApiTestRunner: Executes all API tests
- SmokeTestRunner: Critical functionality only
- RegressionTestRunner: Comprehensive test coverage
- SimpleKarateRunner: Direct execution with detailed logging
Each feature file follows this pattern:
Feature: API Name Tests
Background:
* url baseUrl
@smoke @api-name
Scenario: Positive test scenario
Given path 'endpoint'
When method GET
Then status 200
And match response.field == 'expected'
@negative @api-name
Scenario: Negative test scenario
Given path 'invalid-endpoint'
When method GET
Then status 404
-
Create Feature File
src/test/java/api/new-endpoint/NewEndpoint.feature
-
Follow Naming Convention
- Use descriptive scenario names
- Add appropriate tags (@smoke, @regression, @negative)
- Include API endpoint name in tags
-
Add to Test Runner
@Karate.Test Karate testNewEndpoint() { return Karate.run("classpath:api/new-endpoint").tags("~@ignore"); }
- β Use meaningful scenario descriptions
- β Add both positive and negative test cases
- β Validate response structure and data types
- β Include proper tags for categorization
- β Follow consistent naming conventions
- β Add comments for complex validations
Issue | Solution |
---|---|
Java version mismatch | Ensure Java 11+ is installed and JAVA_HOME is set |
Maven build failures | Run mvn clean compile test-compile |
Test discovery issues | Check JUnit 5 annotations and runner configuration |
Karate script errors | Verify JavaScript syntax in feature files |
Network timeouts | Increase timeout in karate-config.js |
Run tests with debug logging:
mvn test -Dkarate.options="--debug"
name: API Tests
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v3
with:
java-version: '11'
- run: mvn test
- uses: actions/upload-artifact@v3
with:
name: test-reports
path: target/karate-reports/
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-api-tests
) - Follow the existing POM structure and naming conventions
- Add appropriate tags to new scenarios
- Include both positive and negative test cases
- Update README.md when adding new features
- Commit changes (
git commit -am 'Add new API tests'
) - Push to branch (
git push origin feature/new-api-tests
) - Create a Pull Request
- Tests follow POM pattern
- Proper tags are applied
- Both positive and negative scenarios included
- Code is properly documented
- All tests pass locally
This project is created for educational and testing purposes. No license restrictions apply.
Made with β€οΈ using Karate Framework 1.4.1