0

I am new to RestAssured. So tried a simple example. I have tried it in Eclipse. I am getting the jsonException saying

Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized.

What is this '<' ? where it came from I didn't understand.

Here is the code:

package Demo;

import static org.hamcrest.Matchers.equalTo;
import org.testng.annotations.Test;
import groovy.json.JsonException;
import io.restassured.RestAssured;
import static io.restassured.RestAssured.given;

public class AddPlace {
    
    @Test
    public void add_Place() throws JsonException
    {
        
        
        RestAssured.baseURI="https://rahulshettyacademy.com";
        
        given().
        queryParam("key","AIzaSyAck44GPimBLLP7IEgaFHqzweemHonUDjk").
        body("{" + 
                "\"location\":" + 
                "\"lat\": -38.383494," + 
                "\"lng\": 33.427362" + 
                "}," + 
                "\"accuracy\": 50," + 
                "\"name\": \"Frontline house\"," + 
                "\"phone_number\": \"(+91) 983 893 3937\"," + 
                "\"address\": \"29, side layout, cohen 09\"," + 
                "\"types\":[" + 
                "\"shoe park\"," + 
                "\"shop\"" + 
                "]," + 
                "\"website\":\"http://google.com\"," + 
                "\"language\":\"French-IN\"" + 
                "}").
        when().
        post("maps/api/place/add/json").
        then().assertThat().statusCode(200).and().
          body("status", equalTo("OK"));
    }
}

For the above program I got the output like this:

[RemoteTestNG] detected TestNG version 6.7.0
[TestNG] Running:
  C:\Users\AnsumanPrasad\AppData\Local\Temp\testng-eclipse-559804352\testng-customsuite.xml

FAILED: add_Place
groovy.json.JsonException: Lexing failed on line: 1, column: 1, while reading '<', no possible valid JSON value or punctuation could be recognized.
    at groovy.json.JsonLexer.nextToken(JsonLexer.java:86)
    at groovy.json.JsonLexer$nextToken.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:130)
    at io.restassured.internal.path.json.ConfigurableJsonSlurper.parse(ConfigurableJsonSlurper.groovy:97)
    at io.restassured.internal.path.json.ConfigurableJsonSlurper$parse$0.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
    at io.restassured.internal.path.json.ConfigurableJsonSlurper.parseText(ConfigurableJsonSlurper.groovy:83)
    at io.restassured.internal.path.json.ConfigurableJsonSlurper$parseText.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:139)
    at io.restassured.internal.ContentParser.parse(ContentParser.groovy:42)
    at io.restassured.internal.ContentParser$parse.call(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:166)
    at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure.validate(ResponseSpecificationImpl.groovy:478)
    at io.restassured.internal.ResponseSpecificationImpl$HamcrestAssertionClosure$validate$1.call(Unknown Source)
    at io.restassured.internal.ResponseSpecificationImpl.validateResponseIfRequired(ResponseSpecificationImpl.groovy:674)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.PlainObjectMetaMethodSite.doInvoke(PlainObjectMetaMethodSite.java:43)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:193)
    at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:61)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:185)
    at io.restassured.internal.ResponseSpecificationImpl.body(ResponseSpecificationImpl.groovy:261)
    at io.restassured.specification.ResponseSpecification$body$1.callCurrent(Unknown Source)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:51)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:171)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:212)
    at io.restassured.internal.ResponseSpecificationImpl.body(ResponseSpecificationImpl.groovy:108)
    at io.restassured.internal.ValidatableResponseOptionsImpl.body(ValidatableResponseOptionsImpl.java:244)
    at io.restassured.internal.ValidatableResponseImpl.super$2$body(ValidatableResponseImpl.groovy)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:107)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:323)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1262)
    at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.invokeMethodOnSuperN(ScriptBytecodeAdapter.java:144)
    at io.restassured.internal.ValidatableResponseImpl.body(ValidatableResponseImpl.groovy:298)
    at io.restassured.internal.ValidatableResponseImpl.body(ValidatableResponseImpl.groovy)
    at Demo.AddPlace.add_Place(AddPlace.java:41)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:715)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:907)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1237)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:51)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:85)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1197)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1122)
    at org.testng.TestNG.run(TestNG.java:1030)
    at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
    at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
    at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)


===============================================
    Default test
    Tests run: 1, Failures: 1, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.XMLReporter@52af6cff: 77 ms
[TestNG] Time taken by org.testng.reporters.EmailableReporter@9f70c54: 43 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@50f8360d: 23 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@6615435c: 165 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@617c74e5: 97 ms
[TestNG] Time taken by [TestListenerAdapter] Passed:0 Failed:0 Skipped:0]: 12 ms
James Z
  • 12,209
  • 10
  • 24
  • 44
  • An open bracket `{` is missing after `"location" :`, check your payload or use the below `.body("{" + "\"location\":" + "{" + "\"lat\": -38.383494," + "\"lng\": 33.427362" + "}," + "\"accuracy\": 50," + "\"name\": \"Frontline house\"," + "\"phone_number\": \"(+91) 983 893 3937\"," + "\"address\": \"29, side layout, cohen 09\"," + "\"types\":[" + "\"shoe park\"," + "\"shop\"" + "]," + "\"website\":\"http://google.com\"," + "\"language\":\"French-IN\"" + "}")` – Wilfred Clement Jun 24 '20 at 17:42
  • I would suggest you to add `.log().all()` and check the request traffic, Take the payload and validate on jsonlint.com – Wilfred Clement Jun 24 '20 at 17:48
  • 1
    @WilfredClement Thanks a lot. Because of one `{` I faced this problem. – Ansuman Prasad Pati Jun 25 '20 at 09:13

0 Answers0