简体   繁体   中英

Using feeder inside Json in Gatling

I have a json file which looks like below,

 {
 "OrderRef": "Rand12345"
 "siteContactName": "ABC", 
  "siteContactNumber": "12345678", 
  "contactMobileNumber": "12345678", 
  "estimatedDeliveryDate": "2016-03-08", 
  "orderLines": [ 
    { 
      "productCode": "846581",
      "productName": "ABC",
      "quantity": 112, 
      "price": 5.01, 
      "vatAmount": 112.22 
    }, 
    { 
      "productCode": "938169",
      "productName": "DEF", 
      "quantity": 6, 
      "price": 45.03, 
      "vatAmount": 54.04 
    } 
  ]
 "orderNett": 831.30, 
  "orderVatAmount": 166.26, 
  "orderTotal": 997.56 
}

I have to send this Json as a body to a post request, where I have to parametrize OrderRef, productCode and its respective ProductName.

So I created 2 files namely orderref.csv and product.csv, where the orderref.csv has a list of order ids and product.csv has a list of product codes and their respective names. And When I tried this,

class Order extends Simulation {

    val orderref = csv("orderref.csv").random
    val product = csv("product.csv").random

    val scn = scenario("OrderCreation")
    .feed(orderref)
    .feed(product)

    .exec(http("OrderCreation")
    .post("/abc/orders")
    .body("""
          {
     "OrderRef": "${orderref}"
     "siteContactName": "ABC", 
      "siteContactNumber": "12345678", 
      "contactMobileNumber": "12345678", 
      "estimatedDeliveryDate": "2016-03-08", 
      "orderLines": [ 
        { 
 // ProductCode and ProductName are the headers of the columns in my product.csv
          "productCode": "${ProductCode}",
          "productName": "${ProductName}",
          "quantity": 112, 
          "price": 5.01, 
          "vatAmount": 112.22 
        }, 
        { 
          "productCode": "${ProductCode}",
          "productName": "${ProductName}", 
          "quantity": 6, 
          "price": 45.03, 
          "vatAmount": 54.04 
        } 
      ]
     "orderNett": 831.30, 
      "orderVatAmount": 166.26, 
      "orderTotal": 997.56 
    }""").asJson)

    setUp(scn.inject(atOnceUsers(1)))
    }

I get

not found: value ProductCode
not found: value ProductName

But orderref is being accepted. Any suggestions please.

Thanks

Crystal ball: white spaces in your csv files. The CSV spec says to not trim.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM