Karate DSL and Concourse – How to integrate?

Reading Time: 3 minutes

Hi folks,

In this short blog, we will see how to integrate Karate DSL having API tests with the concourse. Since CI/CD is a major thing in the software industry now, we need to have our tests integrated with the CI/CD pipeline that we are using in our respective projects.

This blog is all about integrating Karate with Concourse CI. So, let’s begin.

Setting up Concourse.

Setting up a concourse is not a difficult task, we just need to run a couple of commands and that would suffice. Let me break the process into steps.

  • Create a docker-compose.yml file for setting up the concourse. We can do so by executing the following cURL in our terminal
curl -O https://concourse-ci.org/docker-compose.yml
  • Do a docker compose up for the YAML file created in the above step
docker-compose up -d
  • That’s it, you have now Concourse up and running on port 8080. You can access the pipeline by opening http://localhost:8080/ on your browser.
  • After this, you need to install fly. The Fly tool provides a command-line interface to Concourse. To install, execute the following commands.
$ curl 'http://localhost:8080/api/v1/cli?arch=amd64&platform=linux' -o fly \
$ chmod +x ./fly && mv ./fly /usr/local/bin/
$ fly -t tutorial login -c http://localhost:8080 -u test -p test

This will configure fly and that will be it. Now, we can proceed ahead and create a pipeline. But to create the pipeline and have our Karate tests integrated with it, we need to create a new YAML file for the pipeline. Let’s see how we can do that.

Creating the pipeline for Karate tests.

I didn’t find much on the web with Karate and Concourse. To be honest, I didn’t find it much difficult to have Karate working with the concourse. All you need is a working project based on Karate and a suitably configured YAML file for the pipeline. Firstly, the YAML that I’ve used is pulling up an image of OpenJDK version “1.8.0_312”, because it is mentioned in the Karate document itself that it needs either this version that I’ve mentioned or higher to run smoothly.

So, we have all the pre-requisite satisfied now. All we need to do is, provide the run command so that we can run our Karate tests.

To do so, I’ve created a shell script that has the correct command to run our test. You can find the YAML file and the shell script below.

This is the YAML file that I’ve used to configure the pipeline.

  - name: test
      - get: karate
        trigger: true
      - config:
            - path: $HOME/.m2/repository
          container_limits: {}
            name: ""
              repository: maven
              tag: 3.8.4-openjdk-8-slim
            type: registry-image
            - name: karate
          platform: linux
            path: /bin/sh
              - karate/run.sh
            user: root
        task: run-tests
    public: true

  - icon: github
    name: karate
      uri: ((your_repo_URL_goes_here))
      branch: master
    type: git

The shell script looks something like this.

java -version

cd karate

mvn -Dtest=APIRunner test

And that’s it. We have all the things in place to run our tests on the pipeline. The only thing that is left is to send the updated configurations to the pipeline using “fly”. Let’s see how we can do that.

Sending configurations to the pipeline using fly.

Furthermore, we need to send these pipeline jobs and configurations using fly. We can do so, by using the following command.

fly -t tutorial set-pipeline -p demo -c pipeline.yaml

Moving on, once you have executed this command you will see a message on your terminal screen stating something like this.

the pipeline is currently paused. to unpause, either:
  - run the unpause-pipeline command:
    fly -t tutorial unpause-pipeline -p demo
  - click play next to the pipeline in the web ui

On the concourse dashboard, you can see the pipeline that we have just created but the pipeline is paused currently, it won’t execute. To unpause it, use the following command

fly -t tutorial unpause-pipeline -p demo

Now, we have the pipeline ready to be executed.

Just click on the “+” sign. This will trigger the pipeline.

In the image below, you can see the java version that I’ve used.

That’s all folks. I hope you may have found this useful. Please do check out our other blogs, https://blog.knoldus.com/category/tech-blogs/test-automation/. Thanks!



Written by 

Sparsh is a QA Consultant having experience of more than 2 years. He is familiar with the core concepts of manual and automation, Karate, Cypress, Gatling, Rest Assured and Selenium are the tools that Sparsh is familiar with. He is always eager to learn new and advanced concepts in order to upskill himself.