1

I am using Karate for my automation and javascript code in my after scenario is not working. I have followed the docs(https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/demo/hooks/hooks.feature) very closely.

Feature: sample karate test script    
If you are using Eclipse, install the free Cucumber-Eclipse plugin from
https://cucumber.io/cucumber-eclipse/
Then you will see syntax-coloring for this file. But best of all,
you will be able to right-click within this file and [Run As -> Cucumber Feature].
If you see warnings like "does not have a matching glue code",
go to the Eclipse preferences, find the 'Cucumber User Settings'
and enter the following Root Package Name: com.intuit.karate    
Refer to the Cucumber-Eclipse wiki for more:...

    
Background:
    * url 'https://api.todoist.com/rest/v1/'
    * def headerData = { 'Content-Type' : 'application/json', 'Authorization': 'Bearer 676f2blabla...'}
    * headers headerData
    * configure afterScenario =
    """
    () => {
    var info = karate.info;
    var runId = 27;
    console.log("function afterscenario running happily");
    }
     """
    
Scenario: get all projects of a user

Given path 'projects'
When method get
Then status 200
    And match response[0] contains { id: '#number'}

For some reason this afterScenario never executes. I never get the console log. I have Scenarios following this Background. I wonder if there was a problem with some versions of karate as i see some issues posted. Please point if I am missing something.

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.zemoso</groupId>
<artifactId>make-my-trip-tryagain</artifactId>
<version>1.0-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>1.1.0</karate.version>
</properties>    

<dependencies>         
    <dependency>
        <groupId>com.intuit.karate</groupId>
        <artifactId>karate-junit4</artifactId>
        <version>${karate.version}</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</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-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>       
Abhijeet
  • 689
  • 2
  • 10
  • 19
  • since it may be a bug, please follow this process. if you can't - then we can't fix it: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Aug 09 '21 at 12:03

0 Answers0