Получение этой ошибки при запуске файла запуска теста. «31mio.restassured.path.json.Exception.JsonPathException: не удалJAVA

Программисты JAVA общаются здесь
Ответить Пред. темаСлед. тема
Anonymous
 Получение этой ошибки при запуске файла запуска теста. «31mio.restassured.path.json.Exception.JsonPathException: не удал

Сообщение Anonymous »

Я практикую сквозной сценарий RestAPI. Ниже приведены подробности. Пожалуйста, помогите мне решить проблему.
Мой файл Test Runner:

Код: Выделить всё

package cucumber.Options;

import org.junit.runner.RunWith;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;

@RunWith(Cucumber.class)
@CucumberOptions(
features = "src/test/java/features/placeValidation.feature",
glue = {"stepDefinations"}, plugin={"pretty"}
)
public class TestRunner {

}
Файл определения моего шага:

Код: Выделить всё

package stepDefinations;

import static io.restassured.RestAssured.given;
import static org.junit.Assert.*;

import java.io.IOException;

//import java.util.ArrayList;
//import java.util.List;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
//import io.restassured.builder.RequestSpecBuilder;
import io.restassured.builder.ResponseSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;
import io.restassured.specification.ResponseSpecification;
import resources.APIResource;
//import pojo_serialization.Location;
//import pojo_serialization.googleResponse;
import resources.TestDataBuild;
import resources.Utils;

public class StepDefination extends Utils{
RequestSpecification res;
ResponseSpecification resSpec;
Response response;
TestDataBuild td=new TestDataBuild();
static String  place_id;

@Given("Add Place payload {string} {string} {string}")
public void add_place_payload(String name, String language, String address) throws IOException {
res=given().spec(requestSpecification()).body(td.AddPlacePayload(name, language, address));
}

@When("user calls {string} with {string} http request")
public void user_calls_with_http_request(String resource, String method) {

APIResource resourceAPI=APIResource.valueOf(resource);
resSpec=new ResponseSpecBuilder().expectStatusCode(200).expectContentType(ContentType.JSON).build();
response=res.when().post("maps/api/place/add/json")
.then().spec(resSpec).extract().response();

if (method.equalsIgnoreCase("POST"))
response=res.when().post(resourceAPI.getResource());
else if (method.equalsIgnoreCase("GET"))
response= res.when().get(resourceAPI.getResource());
}

@Then("API call got success with status {int}")
public void api_call_got_success_with_status(Integer int1) {
assertEquals(response.getStatusCode(),200);
//throw new io.cucumber.java.PendingException();
}
@Then("{string} in response body is {string}")
public void in_response_body_is(String keyValue, String expectedValue) {

assertEquals(getJsonPath(response,keyValue),expectedValue);
}
@Then("verify place_id created maps to {string} using {string}")
public void verify_place_id_created_maps_to_using(String expectedName, String resource) throws IOException {

place_id=getJsonPath(response, "place_id");
res=given().spec(requestSpecification()).queryParam("place_id",place_id);
user_calls_with_http_request(resource, "GET");
String Actualname=getJsonPath(response, "name");
assertEquals(Actualname,expectedName);
}

@Given("Delete place payload")
public void delete_place_payload() throws IOException {
res= given().spec(requestSpecification())
.body(td.deleteplacePayload(place_id));

}

}
Мой файл TestDataBuildFile:

Код: Выделить всё

package resources;

import java.util.ArrayList;
import java.util.List;

import pojo_serialization.Location;
import pojo_serialization.googleResponse;

public class TestDataBuild {

public googleResponse AddPlacePayload(String name, String language,  String address)
{
googleResponse g=new googleResponse();
g.setAccuracy(50);
g.setAddress(address);
g.setLanguage(language);
Location l = new Location();
l.setLat(-38.383494);
l.setLng(33.427362);
g.setLocation(l);
g.setName(name);
g.setPhoneNumber("238478273947");
g.setWebsite("www.google.com");
List myList=new ArrayList();
myList.add("Shoepark");
myList.add("shop");
g.setTypes(myList);
return g;
}

public String deleteplacePayload(String place_id)
{
return "{\r\n    \""+place_id+":\"c6dc08bb576960920f2eea2d2c9dfd7c\"\r\n}";
}

}
Мой файл Utils:

Код: Выделить всё

package resources;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Properties;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.filter.log.RequestLoggingFilter;
import io.restassured.filter.log.ResponseLoggingFilter;
import io.restassured.http.ContentType;
import io.restassured.path.json.JsonPath;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

public class Utils {

public static RequestSpecification reqSpec;
public RequestSpecification requestSpecification() throws IOException
{
if(reqSpec==null) {
PrintStream log= new PrintStream(new FileOutputStream("log.txt"));
RequestSpecification reqSpec=new RequestSpecBuilder().setBaseUri(getGlobalValues("baseURI")).addQueryParam("key", "qaclick123")
.addFilter(RequestLoggingFilter.logRequestTo(log))
.addFilter(ResponseLoggingFilter.logResponseTo(log))
.setContentType(ContentType.JSON).build();
return reqSpec;
}
return reqSpec;
}

public String getGlobalValues(String key) throws IOException
{
Properties prop=new Properties();
FileInputStream fis=new FileInputStream("C:\\Users\\ansuman.pati\\eclipse-workspace\\APIFramework\\src\\test\\java\\resources\\globalValue.properties");
prop.load(fis);
return prop.getProperty(key);
}

public String getJsonPath(Response response, String key)
{
String res1=response.asString();
JsonPath js=new JsonPath(res1);
return js.get(key).toString();

}

}
Разместите файл validation.feature.

Код: Выделить всё

Feature: Validating Place API

Scenario Outline: Verify the place is being successfully added using AddPlaceAPI
Given   Add Place payload "" "" ""
When    user calls "AddPlaceAPI" with "POST" http request
Then    API call got success with status 200
And     "status" in response body is "OK"
And     "scope" in response body is "APP"
And     verify place_id created maps to "" using "getPlaceAPI"

Examples:
|name     |language|address     |
|ABunglow |English |Washinton DC|
#|Pizza house|French|USA|

Scenario: Verify if deletePlaceAPI functionality is working.
Given Delete place payload
When  user calls "deletePlaceAPI" with "POST" http request
Then  API call got success with status 200
And   "status"  in response body is "OK"
Файл API Resource.java:

Код: Выделить всё

package resources;

public enum APIResource {

AddPlaceAPI("maps/api/place/add/json"),
getPlaceAPI("maps/api/place/get/json"),
deletePlaceAPI("maps/api/place/delete/json");

public String resource;

APIResource(String resource) {

this.resource=resource;

}

public String getResource()
{
return resource;
}

}
с указанными выше файлами я получаю вывод как:

Код: Выделить всё

Scenario Outline: Verify the place is being successfully added using AddPlaceAPI [90m# src/test/java/features/placeValidation.feature:14[0m
[32mGiven [0m[32mAdd Place payload [0m[32m[1m"ABunglow"[0m[32m [0m[32m[1m"English"[0m[32m [0m[32m[1m"Washinton DC"[0m                    [90m# stepDefinations.StepDefination.add_place_payload(java.lang.String,java.lang.String,java.lang.String)[0m
[32mWhen [0m[32muser calls [0m[32m[1m"AddPlaceAPI"[0m[32m with [0m[32m[1m"POST"[0m[32m http request[0m                         [90m# stepDefinations.StepDefination.user_calls_with_http_request(java.lang.String,java.lang.String)[0m
[32mThen [0m[32mAPI call got success with status [0m[32m[1m200[0m                                      [90m# stepDefinations.StepDefination.api_call_got_success_with_status(java.lang.Integer)[0m
[32mAnd [0m[32m[0m[32m[1m"status"[0m[32m in response body is [0m[32m[1m"OK"[0m                                          [90m# stepDefinations.StepDefination.in_response_body_is(java.lang.String,java.lang.String)[0m
[32mAnd [0m[32m[0m[32m[1m"scope"[0m[32m in response body is [0m[32m[1m"APP"[0m                                          [90m# stepDefinations.StepDefination.in_response_body_is(java.lang.String,java.lang.String)[0m
[32mAnd [0m[32mverify place_id created maps to [0m[32m[1m"ABunglow"[0m[32m using [0m[32m[1m"getPlaceAPI"[0m             [90m# stepDefinations.StepDefination.verify_place_id_created_maps_to_using(java.lang.String,java.lang.String)[0m

Scenario: Verify if deletePlaceAPI functionality is working.  [90m# src/test/java/features/placeValidation.feature:17[0m
[32mGiven [0m[32mDelete place payload[0m                                 [90m# stepDefinations.StepDefination.delete_place_payload()[0m
[32mWhen [0m[32muser calls [0m[32m[1m"deletePlaceAPI"[0m[32m with [0m[32m[1m"POST"[0m[32m http request[0m  [90m# stepDefinations.StepDefination.user_calls_with_http_request(java.lang.String,java.lang.String)[0m
[32mThen [0m[32mAPI call got success with status [0m[32m[1m200[0m                  [90m# stepDefinations.StepDefination.api_call_got_success_with_status(java.lang.Integer)[0m
[31mAnd [0m[31m[0m[31m[1m"status"[0m[31m in response body is [0m[31m[1m"OK"[0m                      [90m# stepDefinations.StepDefination.in_response_body_is(java.lang.String,java.lang.String)[0m
[31mio.restassured.path.json.exception.JsonPathException: Failed to parse the JSON document
at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1002)
at io.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:967)
at io.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:1047)
at io.restassured.path.json.JsonPath.get(JsonPath.java:202)
at resources.Utils.getJsonPath(Utils.java:45)
at stepDefinations.StepDefination.in_response_body_is(StepDefination.java:62)
at ✽."status"  in response body is "OK"(file:///C:/Users/ansuman.pati/eclipse-workspace/APIFramework/src/test/java/features/placeValidation.feature:21)
Caused by: java.lang.IllegalArgumentException:  T h e   J S O N   i n p u t   t e x t   s h o u l d   n e i t h e r   b e   n u l l   n o r   e m p t y . < b r   / >         a t   j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e C o n s t r u c t o r A c c e s s o r I m p l . n e w I n s t a n c e 0 ( N a t i v e   M e t h o d ) < b r   / >         a t   j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . N a t i v e C o n s t r u c t o r A c c e s s o r I m p l . n e w I n s t a n c e ( N a t i v e C o n s t r u c t o r A c c e s s o r I m p l . j a v a : 7 7 ) < b r   / >         a t   j a v a . b a s e / j d k . i n t e r n a l . r e f l e c t . D e l e g a t i n g C o n s t r u c t o r A c c e s s o r I m p l . n e w I n s t a n c e ( D e l e g a t i n g C o n s t r u c t o r A c c e s s o r I m p l . j a v a : 4 5 ) < b r   / >         a t   j a v a . b a s e / j a v a . l a n g . r e f l e c t . C o n s t r u c t o r . n e w I n s t a n c e W i t h C a l l e r ( C o n s t r u c t o r . j a v a : 4 9 9 ) < b r   / >         a t   j a v a . b a s e / j a v a . l a n g . r e f l e c t . C o n s t r u c t o r . n e w I n s t a n c e ( C o n s t r u c t o r . j a v a : 4 8 0 ) < b r   / >         a t   o r g . c o d e h a u s . g r o o v y . r e f l e c t i o n . C a c h e d C o n s t r u c t o r . i n v o k e ( C a c h e d C o n s t r u c t o r . j a v a : 7 3 ) < b r   / >         a t   o r g . c o d e h a u s . g r o o v y . r u n t i m e . c a l l s i t e . C o n s t r u c t o r S i t e $ C o n s t r u c t o r S i t e N o U n w r a p N o C o e r c e . c a l l C o n s t r u c t o r ( C o n s t r u c t o r S i t e . j a v a : 1 0 8 ) < b r   / >         a t   o r g . c o d e h a u s . g r o o v y . r u n t i m e . c a l l s i t e . C a l l S i t e A r r a y . d e f a u l t C a l l C o n s t r u c t o r ( C a l l S i t e A r r a y . j a v a : 5 7 ) < b r   / >         a t   o r g . c o d e h a u s . g r o o v y . r u n t i m e . c a l l s i t e . A b s t r a c t C a l l S i t e . c a l l C o n s t r u c t o r ( A b s t r a c t C a l l S i t e . j a v a : 2 6 3 ) < b r   / >         a t   o r g . c o d e h a u s . g r o o v y . r u n t i m e . c a l l s i t e . A b s t r a c t C a l l S i t e . c a l l C o n s t r u c t o r ( A b s t r a c t C a l l S i t e . j a v a : 2 7 7 ) < b r />    at io.restassured.internal.path.json.ConfigurableJsonSlurper.parseText(ConfigurableJsonSlurper.groovy:80)
at io.restassured.path.json.JsonPath$4$1.method(JsonPath.java:965)
at io.restassured.path.json.JsonPath$ExceptionCatcher.invoke(JsonPath.java:1000)
at io.restassured.path.json.JsonPath$4.doParseWith(JsonPath.java:967)
at io.restassured.path.json.JsonPath$JsonParser.parseWith(JsonPath.java:1047)
at io.restassured.path.json.JsonPath.get(JsonPath.java:202)
at resources.Utils.getJsonPath(Utils.java:45)
at stepDefinations.StepDefination.in_response_body_is(StepDefination.java:62)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at io.cucumber.java.Invoker.doInvoke(Invoker.java:66)
at io.cucumber.java.Invoker.invoke(Invoker.java:24)
at io.cucumber.java.AbstractGlueDefinition.invokeMethod(AbstractGlueDefinition.java:47)
at io.cucumber.java.JavaStepDefinition.execute(JavaStepDefinition.java:29)
at io.cucumber.core.runner.CoreStepDefinition.execute(CoreStepDefinition.java:66)
at io.cucumber.core.runner.PickleStepDefinitionMatch.runStep(PickleStepDefinitionMatch.java:63)
at io.cucumber.core.runner.ExecutionMode$1.execute(ExecutionMode.java:10)
at io.cucumber.core.runner.TestStep.executeStep(TestStep.java:84)
at io.cucumber.core.runner.TestStep.run(TestStep.java:56)
at io.cucumber.core.runner.PickleStepTestStep.run(PickleStepTestStep.java:51)
at io.cucumber.core.runner.TestCase.run(TestCase.java:84)
at io.cucumber.core.runner.Runner.runPickle(Runner.java:75)
at io.cucumber.junit.PickleRunners$NoStepDescriptions.lambda$run$0(PickleRunners.java:151)
at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runTestCase$5(CucumberExecutionContext.java:137)
at io.cucumber.core.runtime.RethrowingThrowableCollector.executeAndThrow(RethrowingThrowableCollector.java:23)
at io.cucumber.core.runtime.CucumberExecutionContext.runTestCase(CucumberExecutionContext.java:137)
at io.cucumber.junit.PickleRunners$NoStepDescriptions.run(PickleRunners.java:148)
at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:144)
at io.cucumber.junit.FeatureRunner.runChild(FeatureRunner.java:28)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at io.cucumber.junit.FeatureRunner.run(FeatureRunner.java:137)
at io.cucumber.junit.Cucumber.runChild(Cucumber.java:196)
at io.cucumber.junit.Cucumber.runChild(Cucumber.java:89)
at org.junit.runners.ParentRunner$4.run(ParentRunner.java:331)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:79)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:329)
at org.junit.runners.ParentRunner.access$100(ParentRunner.java:66)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:293)
at io.cucumber.core.runtime.CucumberExecutionContext.lambda$runFeatures$6(CucumberExecutionContext.java:148)
at io.cucumber.core.runtime.CucumberExecutionContext.execute(CucumberExecutionContext.java:163)
at io.cucumber.core.runtime.CucumberExecutionContext.runFeatures(CucumberExecutionContext.java:146)
at io.cucumber.junit.Cucumber$StartAndFinishTestRun.evaluate(Cucumber.java:226)
at org.junit.runners.ParentRunner$3.evaluate(ParentRunner.java:306)
at org.junit.runners.ParentRunner.run(ParentRunner.java:413)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:529)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:757)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:452)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:210)
[0m
Пожалуйста, предложите, какие изменения мне следует внести, чтобы избавиться от этой проблемы?

Подробнее здесь: https://stackoverflow.com/questions/784 ... red-path-j
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «JAVA»