0

Using the code below, I'm getting the following error:

My code:

    @Test
    public void get_user_API_Schema_Test() {

        RestAssured.baseURI = "https://gorest.co.in";
        given().log().all()
        .contentType(ContentType.JSON)
                .header("Authorization", "Bearer _FWTKt73f0EeVrfWj7d3sKoLMnw_9dqVcs0k")
                    .when().log().all()
                .get("/public-api/users?first_name=Reina&gender=male&status=active")
                    .then().log().all()
                        .assertThat()
                .statusCode(200).and().body(matchesJsonSchemaInClasspath("C:\\Users\\ASHUTOSH SINGH\\eclipse-workspace\\RestAPI2020\\src\\test\\java\\com\\rest\\api\\schema\\getuserschema.json"));

    }

Returns the following error:

FAILED: get_user_API_Schema_Test
java.lang.IllegalArgumentException: Schema to use cannot be null
    at io.restassured.module.jsv.JsonSchemaValidator.validateSchemaIsNotNull(JsonSchemaValidator.java:270)
    at io.restassured.module.jsv.JsonSchemaValidator.access$300(JsonSchemaValidator.java:75)
    at io.restassured.module.jsv.JsonSchemaValidator$JsonSchemaValidatorFactory.create(JsonSchemaValidator.java:281)
    at io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchema(JsonSchemaValidator.java:166)
    at io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath(JsonSchemaValidator.java:117)
    at com.rest.api.schema.CheckSchemaTest.get_user_API_Schema_Test(CheckSchemaTest.java:43)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
    at org.testng.TestRunner.privateRun(TestRunner.java:648)
    at org.testng.TestRunner.run(TestRunner.java:505)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
    at org.testng.SuiteRunner.run(SuiteRunner.java:364)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
    at org.testng.TestNG.runSuites(TestNG.java:1049)
    at org.testng.TestNG.run(TestNG.java:1017)
    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
===============================================
4
  • 2
    The file path should be relative to class path , try statusCode(200).and().body(matchesJsonSchemaInClasspath("\\test\\java\\com\\rest\\api\\schema\\getuserschema.json")); orstatusCode(200).and().body(matchesJsonSchemaInClasspath(".\\test\\java\\com\\rest\\api\\schema\\getuserschema.json")); or statusCode(200).and().body(matchesJsonSchemaInClasspath("test\\java\\com\\rest\\api\\schema\\getuserschema.json")); – PDHide Aug 27 '20 at 8:34
  • 1
    Any update ? On this – PDHide Aug 31 '20 at 20:41
  • 1
    Yeah It has been resolve after your help, thanks – Ashutosh Singh Aug 31 '20 at 20:58
  • I have added it as answer could you please accepth and upvote – PDHide Sep 1 '20 at 8:38
2

The file path should be relative to class path , try statusCode(200).and().body(matchesJsonSchemaInClasspath("\\test\\java\\com\\rest\\api\\schema\\getuserschema.json"));

or

statusCode(200).and().body(matchesJsonSchemaInClasspath(".\\test\\java\\com\\rest\\api\\schema\\getuserschema.json"));

or

statusCode(200).and().body(matchesJsonSchemaInClasspath("test\\java\\com\\rest\\api\\schema\\getuserschema.json"));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.