如何在硒中使用RestAssured发布以下请求 [英] How to Post the below request using RestAssured in selenium

查看:107
本文介绍了如何在硒中使用RestAssured发布以下请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在硒中使用RestAssured张贴以下请求.

How to POST the below request using RestAssured in selenium.

请求如下:

{
  "ShipmentID": "",
 "ShipmentNumber": "123455-6", 
 "Comments": "",
 "LineIDs": [
    {
  "ShipmentDID": "",  
  "AssetNum": "759585",
  "FileC": "",
  "SerialN": "",
  "LineID": "5",
  "Status": "Accept",
  "TransferCancelComment": ""
}

下面是我使用过的代码,但不确定该如何继续使用"LineID",因为其中包含的属性很少.

Below is the code I have used but not sure how should i continue for the "LineID's" as it has few more attributes in it.

@Test
 public void TransferIn() {

  RestAssured.baseURI="testurl.rest.com";
  RequestSpecification httpRequest = RestAssured.given();
  JSONObject requestparams=new JSONObject();
  try {
      requestparams.put("ShipmentID", "");
      requestparams.put("ShipmentNumber", "123455-6");
      requestparams.put("Comments", "");
      requestparams.put("LineIDs", "");

  }

推荐答案

希望以下代码可以解决您的问题.

Hope below code will solve your problem.

    @Test
    public void TransferIn() {
        RestAssured.baseURI="testurl.rest.com";
        RequestSpecification httpRequest = RestAssured.given();
        JSONObject requestparams = new JSONObject();
        JSONArray lineIdsArray = new JSONArray();
        JSONObject lineIdObject = new JSONObject();
        try {
            requestparams.put("ShipmentID", "");
            requestparams.put("ShipmentNumber", "123455-6");
            requestparams.put("Comments", "");

            lineIdObject.put("ShipmentDID", "");
            lineIdObject.put("AssetNum", "759585");
            lineIdObject.put("FileC", "");
            lineIdObject.put("SerialN", "");
            lineIdObject.put("LineID", "5");
            lineIdObject.put("Status", "Accept");
            lineIdObject.put("TransferCancelComment", "");
            lineIdsArray.put(lineIdObject);

            requestparams.put("LineIDs", lineIdsArray);
        } catch (JSONException e) {

        }
        System.out.println(requestparams);
}

这篇关于如何在硒中使用RestAssured发布以下请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆