-2

I am trying to run an API test with basic info through karate feature file.

<--------------------------------------Feature file content----------------------------------->

Feature: Relationship Service validation
Scenario: Get drill-down nodes when filter has contains condition operator
Given url 'http://localhost:9999/normal/webapi/all'
When method get
Then status 200

<--------------------------------------Testcase Runner Class----------------------------------->

import com.intuit.karate.junit5.Karate;
import com.intuit.karate.junit5.Karate.Test;
//import com.intuit.karate.core.
public class TestGetRunner {
@Test
public Karate runTest(){
    return Karate.run("getRequest").relativeTo(getClass());
}
}

I think I have added all dependancies. But while running the test through Junit, I am getting error:

1 < Connection: keep-alive
[{"jobId":1,"jobTitle":"Software Engg","jobDescription":"To develop andriod 
application","experience":["Google","Apple","Mobile Iron"],"project":[{"projectName":"Movie 
App","technology":["Kotlin","SQL Lite","Gradle"]}]}]
18:53:27.126 [main] ERROR com.intuit.karate - 
classpath:com/api/automation/getrequest/getRequest.feature:5
When method get
Could not initialize class com.intuit.karate.JsonUtils
classpath:com/api/automation/getrequest/getRequest.feature:5

API is working fine and the above shown list of jsons is the output. But with line no. 5, I am getting error "Could not initialize class com.intuit.karate.JsonUtils". I can see the JsonUtils class available. But don't know why its object couldn't be created. I did inspect karate framework code line-by-line. But no help. I am new to Karate automation. Please help if anyone aware of this!

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
GANASH A
  • 1
  • 1
  • this is working for me and everyone else. follow this process if you can, or you are welcome to try other options: https://github.com/intuit/karate/wiki/How-to-Submit-an-Issue – Peter Thomas Apr 22 '21 at 14:18
  • The duplicate question already answered, didn't help me out. It deals with Summary report. But my Question is with a JAVA concept. FYI - I have moved my repo to github https://github.com/aganashcse/karateframeworktutorial – GANASH A Apr 22 '21 at 14:56
  • I have re-opened your question. lets hope someone in the community helps you - based on the info you have provided – Peter Thomas Apr 22 '21 at 17:26

1 Answers1

1

I just executed your code with different URL https://reqres.in/api/users/2 and it's working for me.

My environment:

C:\>mvn -v
Apache Maven 3.6.3 ()
Maven home: C:\apache-maven\bin\..
Java version: 14.0.2, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-14.0.2
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"

Output:

C:\karateframeworktutorial-master-working>mvn clean test
[INFO] Scanning for projects...
[INFO]
[INFO] -------------< com.api.automation:karateframeworktutorial >-------------
[INFO] Building karateframeworktutorial 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ karateframeworktutorial ---
[INFO] Deleting C:\karateframeworktutorial-master-working\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ karateframeworktutorial ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\karateframeworktutorial-master-working\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ karateframeworktutorial ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ karateframeworktutorial ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ karateframeworktutorial ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to C:\karateframeworktutorial-master-working\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ karateframeworktutorial ---
[INFO]
[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] Running com.api.automation.getrequest.TestGetRunner
12:53:38.712 [main] DEBUG com.intuit.karate.Suite - [config] classpath:karate-config.js
12:53:39.475 [main] INFO  com.intuit.karate - karate.env system property was: null
12:53:39.742 [main] DEBUG com.intuit.karate - request:
1 > GET https://reqres.in/api/users/2
1 > Host: reqres.in
1 > Connection: Keep-Alive
1 > User-Agent: Apache-HttpClient/4.5.13 (Java/14.0.2)
1 > Accept-Encoding: gzip,deflate


12:53:40.054 [main] DEBUG com.intuit.karate - response time in milliseconds: 281
1 < 200
1 < Date: Thu, 22 Apr 2021 17:53:40 GMT
1 < Content-Type: application/json; charset=utf-8
1 < Transfer-Encoding: chunked
1 < Connection: keep-alive
1 < X-Powered-By: Express
1 < Access-Control-Allow-Origin: *
1 < Etag: W/"118-pbdwwFo9SKNhD3Lx5iHJyngpq00"
1 < Via: 1.1 vegur
1 < Cache-Control: max-age=14400
1 < CF-Cache-Status: HIT
1 < Age: 3340
1 < cf-request-id: 099c5065110000615851bba000000001
1 < Expect-CT: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
1 < Report-To: {"max_age":604800,"group":"cf-nel","endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report?s=P4%2Bq0DOE555WKP3jOZmCrty4XBs1aCszh7CIoqXLwdtVCIIpFcKucIeRgq06UnrhrOmq%2FSCaMlhmAuZ%2BnYZoVPsV2cYjxUG1UpM%3D"}]}
1 < NEL: {"report_to":"cf-nel","max_age":604800}
1 < Vary: Accept-Encoding
1 < Server: cloudflare
1 < CF-RAY: 6440b681bf3f6158-ORD
1 < alt-svc: h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400
1 < Set-Cookie: __cfduid=ddc5fe520d8c7faaa91efe44cc55007481619114020; Max-Age=1621706020000; Expires=Sat, 16 Feb 53411 08:20:20 GMT; Domain=reqres.in; Secure
{"data":{"last_name":"Weaver","id":2,"avatar":"https:\/\/reqres.in\/img\/faces\/2-image.jpg","first_name":"Janet","email":"janet.weaver@reqres.in"},"support":{"text":"To keep ReqRes free, contributions towards server costs are appreciated!","url":"https:\/\/reqres.in\/#support-heading"}}
---------------------------------------------------------
feature: classpath:com/api/automation/getrequest/getRequest.feature
scenarios:  1 | passed:  1 | failed:  0 | time: 0.5520
---------------------------------------------------------

Karate version: 1.0.1
======================================================
elapsed:   1.82 | threads:    1 | thread time: 0.55
features:     1 | skipped:    0 | efficiency: 0.30
scenarios:    1 | passed:     1 | failed: 0
======================================================

HTML report: (paste into browser to view) | Karate version: 1.0.1
file:///C:/karateframeworktutorial-master-working/target/karate-reports/karate-summary.html
===================================================================

[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.317 s - in com.api.automation.getrequest.TestGetRunner
[INFO]
[INFO] Results:
[INFO]
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  5.417 s
[INFO] Finished at: 2021-04-22T12:53:41-05:00
[INFO] ------------------------------------------------------------------------