我需要在一个场景中创建一个Map并动态添加键值对,然后将该Map传递到另一个场景,在该场景中我可以按键检索值。有人能告诉我怎么做吗。
def createData() = {
feed(customFeeder).exec(http("create dataset").post("/datasets").header("content-type", "application/json")
.body(StringBody("""{ "name": "${name}","description": "create dataset"}"""))
.asJson.check(jsonPath("$.id").saveAs("userId")))
.exec(session => {
val name = session("name").asOption[String]
println("Dataset name ::: "+name.getOrElse("COULD NOT FIND NAME"))
val datasetId = session("userId").as[String].trim
println("Dataset ID retrieved from createDataSet Response ::: "+ datasetId)
val datasetIdList = session("datasetIdList").asOption[List[String]].getOrElse(Nil)
println("Upload Start Time :::"+Calendar.getInstance().getTime)
**// add above datasetId, upload start time to the map**
session.set("datasetIdList", userId :: datasetIdList)
})
}
// File Upload for the datasets in the datasetIdList
def fileUpload() = foreach("${datasetIdList}","datasetId"){
// println("File Upload Start Time::::"+Calendar.getInstance().getTime+" for datasetId ::: ${datasetId}")
exec(http("file upload").post("/compute-metaservice/datasets/${datasetId}/uploadFile")
.formUpload("File","./src/test/resources/data/Scan_good.csv")
.header("content-type","multipart/form-data")
.check(status is 200).check(status.saveAs("uploadStatus")))
.exec(session => {
**// retrieve the upload time by datasetId from map above**
session
})
}
val scn1 = scenario("create multiple datasets and upload").exec(createDatasetsAndUpload()).exec(fileUpload())
setUp(scn1.inject(atOnceUsers(3))).protocols(httpConf)
1条答案
按热度按时间fdx2calv1#
第一步:需要为存储会话定义变量
然后我们创建两种方法,在不同的场景中保存和获取会话:
并使用它: