-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Get Started: Maven and Gradle
IntelliJ includes Maven and installing Java would be easier.
If you want to try that route, go here: Get Started: JetBrains IntelliJ
Maven requires a Java Development Kit to be installed. You can get one here: https://www.oracle.com/java/technologies/downloads/
Note that OpenJDK also works.
Maven can be downloaded from here: https://maven.apache.org/download.cgi - and then follow the installation instructions.
Karate Maven projects are recommended to have a particular directory structure and pom.xml
. The options below give you a ready-to-use project with both in place.
- Recommended: You can use the Karate GitHub Template
- Or generate a fresh Maven project locally using the Maven Archetype.
If you want to create a pom.xml
yourself (or add Karate as a dependency to an existing project) you can use the below snippet. But make sure you refer to the documentation on naming conventions and how to run tests.
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-core</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
The latest Karate version can always be found here.
Use the Karate Maven archetype to create a skeleton project with one command. Or if you want to clone a sample GitHub project, skip to the GitHub Template below.
If you are behind a corporate proxy, or especially if your local Maven installation has been configured to point to a repository within your local network, the command below may not work. One workaround is to temporarily disable or rename your Maven
settings.xml
file, and try again.
You can replace the values of com.mycompany
and myproject
as per your needs. Instead of X.X.X
use the version of Karate that you want. The latest version can always be found here.
mvn archetype:generate \
-DarchetypeGroupId=com.intuit.karate \
-DarchetypeArtifactId=karate-archetype \
-DarchetypeVersion=X.X.X \
-DgroupId=com.mycompany \
-DartifactId=myproject
This will create a folder called myproject
(or whatever you set the name to).
Now you can run the example tests using mvn test
. Go to the /target/karate-reports
folder to see the HTML reports.
You will need Git installed or an IDE that has Git support built-in.
Note that a simpler way to get started is to use GitHub Codespaces - and you don't need to install anything locally
- Clone this GitHub project: karate-template
git clone https://github.com/karatelabs/karate-template.git
- If you have Maven installed, you can open a terminal, run
mvn test
and see the results. - Or you can choose to open the project folder in Visual Studio Code and follow the instructions here to run
users.feature
: Visual Studio Code - You can also open this project in IntelliJ with the Karate plugin installed: JetBrains IntelliJ
- To use Gradle, read the section below.
- Install Gradle by following the instructions here: https://gradle.org/install
- Clone the GitHub Template or download that project as a ZIP file and extract it
- A more complicated GitHub project you could clone is karate-test
- You can get a sample Gradle file from this wiki page. Save it as
build.gradle
in the newly created project folder- Optionally, you can also delete the
pom.xml
file which is only for Maven
- Optionally, you can also delete the
- Run this command:
gradle test
- You can also do
gradle test --info
to see the log output and HTTP traffic on the console
- You can also do
- Go to the
/build/karate-reports
folder to see the HTML reports. - You can also open the Gradle project in IntelliJ and use the official Karate plugin