1
votes

I have followed the steps in Karate documentation to create a project, I ran the example test cases given in the default archifect , My cases got passed but i'm not getting any report

my pom.xml

<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>com.poc.karate</groupId>
<artifactId>interacKarate</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.6.0</maven.compiler.version>
</properties>    

<dependencies>    
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit4</artifactId>
        <version>0.2.7</version>
        <scope>test</scope>
    </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-surefire-plugin</artifactId>
            <version>2.10</version>
            <configuration>
            <argLine>-Dfile.encoding=UTF-8</argLine>
            </configuration>
     </plugin>
        <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>
    </plugins>        
</build>       

RunnerClass

package examples.users;

import com.intuit.karate.junit4.Karate;
import org.junit.runner.RunWith;

@RunWith(Karate.class)
public class UsersRunner {

}

my feature file is

Feature: sample karate test script

Background: * url 'https://jsonplaceholder.typicode.com'

Scenario: get all users and then get the first user by id

Given path 'users' When method get Then status 200

  • def first = response[0]

Given path 'users', first.id When method get Then status 200

Scenario: create a user and then get it by id

  • def user = """ { "name": "Test User", "username": "testuser", "email": "[email protected]", "address": { "street": "Has No Name", "suite": "Apt. 123", "city": "Electri", "zipcode": "54321-6789" } } """

Given url 'https://jsonplaceholder.typicode.com/users' And request user When method post Then status 201

  • def id = response.id
  • print 'created id is: ' + id

What else I'm missing here?

1

1 Answers

2
votes

This is a really old version of Karate and I'm sure you are following outdated instructions. I suggest you follow the quick-start: https://github.com/intuit/karate#quickstart

mvn archetype:generate \
-DarchetypeGroupId=com.intuit.karate \
-DarchetypeArtifactId=karate-archetype \
-DarchetypeVersion=0.8.0 \
-DgroupId=com.mycompany \
-DartifactId=myproject