mercredi 13 novembre 2019

Karate Test failing with file not found exception for karate-html.log file

Getting file not exception when running karate test java.lang.RuntimeException: java.io.FileNotFoundException: target\karate-html.log (The system cannot find the path specified)

Code:

@RunWith(Karate.class)
public class KarateTest {

  private static WireMockServer wireMockServer
  = new WireMockServer();

  @BeforeClass
  public static void setUp() throws Exception {
    configureFor("localhost",8484);wireMockServer.
    stubFor(
        get(urlEqualTo("/user/get"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody("{ \"id\": \"1234\", name: \"John Smith\" }")));

    stubFor(
        post(urlEqualTo("/user/create"))
            .withHeader("content-type", equalTo("application/json"))
            .withRequestBody(containing("id"))
            .willReturn(
                aResponse()
                    .withStatus(200)
                    .withHeader("Content-Type", "application/json")
                    .withBody("{ \"id\": \"1234\", name: \"John Smith\" }")));
  }

  @AfterClass
  public static void tearDown() throws Exception {
      wireMockServer.stop();
  }
}

Feature file:

Feature: User Details

  Scenario: Testing valid GET endpoint
    Given url 'http://localhost:8080/user/get'
    When method GET
    Then status 200

  Scenario: Testing the exact response of a GET endpoint
    Given url 'http://localhost:8080/user/get'
    When method GET
    Then status 200
    And match $ == {id:"1234",name:"John Smith"}

  Scenario: Testing that GET response contains specific field
    Given url 'http://localhost:8080/user/get'
    When method GET
    Then status 200
    And match $ contains {id:"1234"}

  Scenario: Testing a POST endpoint with request body
    Given url 'http://localhost:8080/user/create'
    And request { id: '1234' , name: 'John Smith'}
    When method POST
    Then status 200
    And match $ contains {id:"#notnull"}

Project Structure: src-->integrationTest-->java-->com.xyz.user-->KarateTest.java user.feature

So both class and feature file in same package com.xyz.user, but when I run the class, it throws file not found exception.

Any help?

Aucun commentaire:

Enregistrer un commentaire