DEV Community

Khushi Singla
Khushi Singla

Posted on

Seamless API Test Automation: Integrating Karate Framework with Jenkins

Ensuring your APIs remain reliable with every new release can be time-consuming—unless you automate it. Integrating Karate, a powerful API testing framework, with Jenkins, your go-to CI/CD server, can drastically reduce manual testing efforts and catch issues early in the development cycle.

In this blog post, you’ll learn how to set up and run Karate tests in Jenkins, create beautiful reports, and leverage advanced configuration to fit your workflow.


What is Karate?

Karate is an open-source API test automation framework that combines API test-automation, mocks, performance-testing, and even UI automation into a single unified framework. Built on top of Cucumber, it uses Gherkin syntax for writing test scenarios in plain language, making it ideal for both developers and testers.


Why Integrate Karate with Jenkins?

Here's why this duo is a win-win:

  1. Automated Testing — Run API tests automatically after each commit.
  2. Early Bug Detection — Catch regressions before they hit production.
  3. Efficient Workflow — Save time by reducing manual testing.
  4. Real-Time Feedback — Get detailed, instantly available test reports.
  5. Improved Code Quality — Continuous testing ensures confidence in code changes.
  6. Scalability — Supports parallel testing for large test suites.
  7. Toolchain Friendly — Plays nicely with other Jenkins plugins (like JUnit, HTML Publisher).
  8. Centralized Management — Control everything from Jenkins' UI.

Karate and Jenkins Integration & Execution Flow

Integration Steps (Setup Phase)

Karata and Jenkins Integration

Execution Steps (Per Build)

Steps


Prerequisites

Make sure the following are in place before you begin:

  • Jenkins installed and running
  • Plugins: Pipeline, Git, and JUnit
  • A Karate test project (Maven-based)
  • Your code hosted in a version control system (e.g., GitHub)

Jenkins + Karate Integration: Step-by-Step

Step 1. Create a New Jenkins Pipeline

  1. Open Jenkins and log in.
  2. Click on “New Item” from the dashboard.
  3. Enter a name for your pipeline job.
  4. Select “Pipeline” and click OK.

Step 2. Configure the Pipeline

Option 1: Using Inline Script
Paste the following pipeline script under the Pipeline section:

pipeline {
    agent {
        node {
            label 'spot_security'
        }
    }
    tools {
        maven 'sonar-maven'
        jdk 'OpenJDK-11'
    }
    stages {
        stage('Karate Test') {
            steps {
                script {
                    try {
                        sh "mvn test -Dtest=<TestRunner> -s mvnsettings.xml"
                    } catch (Exception e) {
                        currentBuild.result = 'UNSTABLE'
                    }
                }
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Option 2: Using Jenkinsfile from SCM
Select "Pipeline script from SCM"

  1. Choose Git as SCM
  2. Set Repository URL: https://github.com/your-org/your-repo.git
  3. Set Script Path: Jenkinsfile

Step 3. Add Karate to your pom.xml

<dependencies>
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit5</artifactId>
        <version>1.4.0</version> <!-- Or latest -->
        <scope>test</scope>
    </dependency>
</dependencies>

Enter fullscreen mode Exit fullscreen mode

Advanced Configurations

1. Passing Environment Variables

Want to inject dynamic values (e.g., base URLs) into your tests?
Update the pipeline like so:

stage('Karate Test') {
    steps {
        script {
            try {
                sh "mvn test -Dtest=<TestRunner> -Dkarate.env=${params.TEST_ENV} -s mvnsettings.xml"
            } catch (Exception e) {
                currentBuild.result = 'UNSTABLE'
            }
        }
    }
}

Enter fullscreen mode Exit fullscreen mode

Ensure your karate-config.js handles karate.env appropriately.

2. Publish Karate Test Report in Jenkins

To generate a nice HTML report for each test run, use the publishHTML plugin.

stage('Publish Karate Report') {
    steps {
        script {
            try {
                publishHTML(target: [
                    allowMissing: false,
                    alwaysLinkToLastBuild: true,
                    keepAll: true,
                    reportDir: 'target/cucumber-html-reports',
                    reportFiles: 'overview-features.html',
                    reportName: 'Karate Test Report'
                ])
            } catch (Exception e) {
                currentBuild.result = 'UNSTABLE'
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

⚠️ Make sure karate.output.path is not overridden in your project if you rely on the default report location.


Running the Pipeline

  • Trigger manually from Jenkins UI
  • Or set up automatic triggers:
    • Poll SCM (e.g., H/5 * * * *)
    • Webhook-based triggering from GitHub/GitLab/etc.

Once triggered:

  • Watch logs in Console Output
  • Navigate to Published Reports for visual test summaries

Conclusion

Integrating Karate with Jenkins allows teams to automate API tests as part of their CI/CD pipeline. This ensures higher code quality, early bug detection, and streamlined collaboration between QA and development. With minimal setup, you’ll save hours of manual regression testing and boost release confidence.


Further Reading

📘 Official Karate Documentation
🧪 Karate GitHub Repository
📦 Karate on Maven Central
🎓 Karate Tutorials on GitHub
📺 Karate YouTube Channel
💡 Karate Changelog & Release Notes

Top comments (0)