Configuration of KarateDSL Automation Framework in 5 Simple Steps

Priyanka Brahmane
4 min readMar 4, 2021

Buenos días TestCommunity!!

I’m back with the second blog of my Karate series. In this blog, we shall be looking at the setup and configurations required to get started with KarateDSL using Eclipse IDE.

If you skipped the first blog in this series, you may catch up by clicking on this link!!!

Pre-requisites to begin with KarateDSL:

KarateDSL is much easier to use since it only requires a few of the elements mentioned below:

As the setup is hassle-free and lucid, it offers QA Automation professionals a major reason for acceptance.

How do I create Karate API Automation Framework ?

Make sure that Java should be installed and configured on your system before following the steps below. (In case you are facing any difficulty in installation, check out this page)

Step 1: Start up an IDE of your choice (I am using Eclipse IDE with Java).

In case you wish to use IntelliJ, check this video for step-by-step implementation.

Step 2: To create a new maven project, either click the File tab in the top menu > New > Project , or right-click in the Project Explorer section > New > Project. We will be landed to below pop-up on following any of these flows.

Step 3: On selecting Maven Project, click on Next. You’ll arrive at the following pop-up.

Step 4: Click Next again to “Select an Archetype” and type “Karate” in the filter search box as shown below > Hit Enter. (You will see a “retrieving archetypes” progress bar in the bottom-right corner) > Once the retrieval is complete, you will get the latest version of the karate archetypes.

Step 5: Click on next > Enter “Group Id” (a unique base name of the company or group that created the project) and “Artifact Id” (a unique name of the project) — Naming depends on your choice.

And Click on Finish.

Tada!! Congratulations!! Using maven, you’ve successfully created your first Karate framework.

The created project is displayed on the Eclipse IDE under Package Explorer (located on the left-hand side).

Karate Framework Skeleton

Please note, that a Runner file will be created automatically within your package. Its purpose is to run feature files while taking into account the tags that are used for any feature or scenario. The feature/scenario with the tag “@ignore” will not be executed.

After entering proper filename or feature package location, “Run” this runner file in order to generate report.

import com.intuit.karate.Results;import com.intuit.karate.Runner;import static org.junit.Assert.*;import org.junit.Test;public class UserRunner {@Testpublic void testParallel() {Results results = Runner.path("classpath:package_name/file_name.feature").tags("~@ignore").parallel(5);assertTrue(results.getErrorMessages(), results.getFailCount() == 0);}}

After feature file execution, you will see the report location created and stored locally under “target” folder. You will have to copy this location and paste it on browser to see karate report.

This is how the pom.xml file looks after creation of maven project —

<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>API_Automation</groupId><artifactId>Karate_API_Automation</artifactId><version>0.0.1-SNAPSHOT</version><packaging>jar</packaging><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><java.version>1.8</java.version><maven.compiler.version>3.8.1</maven.compiler.version><maven.surefire.version>2.22.2</maven.surefire.version><karate.version>0.9.9.RC4</karate.version></properties><dependencies><!-- https://mvnrepository.com/artifact/com.intuit.karate/karate-junit5 --><dependency><groupId>com.intuit.karate</groupId><artifactId>karate-junit5</artifactId><version>${karate.version}</version></dependency></dependencies>
<build><testResources><testResource><directory>src/test/java</directory><excludes><exclude>**/*.java</exclude></excludes></testResource></testResources><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><version>${maven.compiler.version}</version><configuration><encoding>UTF-8</encoding><source>${java.version}</source><target>${java.version}</target><compilerArgument>-Werror</compilerArgument></configuration></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-surefire-plugin</artifactId><version>${maven.surefire.version}</version><configuration><argLine>-Dfile.encoding=UTF-8</argLine></configuration></plugin></plugins></build></project>

Note: If you are facing “Missing artifact com.intuit.karate:karate- junit5:jar:1.0.0” error on pom.xml, you can navigate here to get the latest “karate-junit5” maven-dependency.

We’ve now created an API framework; in the next post, we’ll delve further into KarateDSL’s core concepts.

Did you find this blog informative? Please leave your thoughts in the comments section below, and be sure to click the Follow button to keep up with the latest news. You can contact me via LinkedIn.

Until then, stay safe and keep learning !!!

--

--

Priyanka Brahmane

AM SDET Automation @M&G | QA Lead @ MyGlamm | QA Automation engineer @ Ex-Paytm Insider| Ex-Automation Tester @ Reliance Jio Infocomm Ltd. | Ex-Software Develop