Неверные идентификаторы в RestAssured POST Call - PullRequest
0 голосов
/ 26 апреля 2020

В RestAssured Automation с использованием POST Call, я получаю исключение Invalid Parameters в моем теле ответа. Я создал JSONObject в качестве requestparams и использовал requestparams для добавления значений json, как я уже упоминал в своем коде.

Мои утверждения также не удалось выполнить в тестовом примере

Моя ошибка похожа на эту :

2020-04-26 20:00:23 INFO  EmployeesRestAPI:46 - <-------Checking Response Body-------->
2020-04-26 20:00:23 INFO  EmployeesRestAPI:48 - The Response Body is ==>{"name":"BadRequest","message":"Invalid Parameters","code":400,"className":"bad-request","data":{},"errors":["should have required property 'name'","should have required property 'type'","should have required property 'upc'","should have required property 'description'","should have required property 'model'"]}
2020-04-26 20:00:23 INFO  EmployeesRestAPI:56 - <------Checking Status Code------->
2020-04-26 20:00:23 INFO  EmployeesRestAPI:58 - The Status Code is ==>400
2020-04-26 20:00:23 INFO  EmployeesRestAPI:100 - <------Ending TC_003_Post_SingleEmployeeDetil-------->

Can anybody give me the Solution.

Ниже мой код

пакет org.com.projectname.testcases;

 import org.com.projectname.testbase.TestBase;
    import org.com.projectname.utilities.RestUtils;
    import org.json.simple.JSONObject;
    import org.testng.Assert;
    import org.testng.annotations.AfterClass;
    import org.testng.annotations.BeforeClass;
    import org.testng.annotations.Test;

    import io.restassured.RestAssured;
    import io.restassured.http.Method;
    import io.restassured.response.Response;


   import io.restassured.specification.RequestSpecification;

    public class TC_003_Post_SingleEmployeeDetail extends TestBase{


        @BeforeClass
        public void postSingleEmployee() throws InterruptedException {
            logger.info("<---------Starting TC_003_Post_SingleEmployeeDetail------->");
            RestAssured.baseURI="http://localhost:3030";
            httprequest = RestAssured.given();
            JSONObject requestparams= new JSONObject();

            requestparams.put("name", "TVS Apache");
            requestparams.put("type", "Bike");
            requestparams.put("price", 70000);
            requestparams.put("upc", "Hondaupc");
            requestparams.put("shipping", 100);
            requestparams.put("description", "TVS Bike with Dual disc Brake, speed upto 160kmp");
            requestparams.put("manufacturer", "TVS");
            requestparams.put("model", "160CC");
            requestparams.put("url", "http://www.TVSBikes.com/TVSApache");
            requestparams.put("image", "http://www.TVSBikes.com/Image=TVSApache");

            httprequest.header("Content_Type", "application/json");
            httprequest.body(requestparams.toString());

            response = httprequest.request(Method.POST, "/products");
            Thread.sleep(5000);
            }

        @Test
        public void checkResponseBody() {
            logger.info("<-------Checking Response Body-------->");
            String responsebody = response.getBody().asString();
            logger.info("The Response Body is ==>"+responsebody);
            Assert.assertEquals(responsebody.contains("TVS Apache"), true);
            Assert.assertEquals(responsebody.contains("Bike"), true);
            Assert.assertEquals(responsebody.contains("160CC"), true);
            }
...