对于Scala / Gatling来说,这是一个陌生的东西,我对SO进行了很多搜索,但是没有任何针对我的问题的解答。所以这是我的代码
val adminUplFile: ScenarioBuilder = scenario("Admin user uploads file")
.exec(http("Upload File")
.post("/file")
.header("username", "example") r
.header("password", "80HL/d1fETqxuCArAbIU6/Sb3F2nSTCqw/eqw1lzJio=")
.formUpload("file", "uploadFile") // body params ("key" , "path of the file/name")
.formParamSeq(Seq(("uploadByID", "1"), ("location", "meetings"), ("personID", "0"), ("uploadTimeStamp", "2019-01-15 10:01:04.426"), ("md5Hash", "n95QI48+Uqxfw0hTnJdqMA==")))
.check(status.is(200))
.check(jsonPath("$.uuid").saveAs("guidList")))
.exec { session =>
val writer = new PrintWriter(new FileOutputStream(new File("src/gatling/resources/extractedData/GuidList.json"), true))
writer.write(session("\"guidList\"").as[String].trim)
writer.write("\n")
writer.close()
session }
setUp(
adminUplFile.inject(constantUsersPerSec(2) during (1 seconds)).protocols(httpConf)
)
这是我尝试提取的响应:
{
"uuid": "3a917e22-3c76-45de-a104-4e2aa4b72a35"
}
所以我写到文件的是:
“ 3a917e22-3c76-45de-a104-4e2aa4b72a35”
“ 929c89c0-7a1a-4a18-8ee8-2958c9cd430f”
我想要的是:
[
“ 3a917e22-3c76-45de-a104-4e2aa4b72a35”,
“ 929c89c0-7a1a-4a18-8ee8-2958c9cd430f”
]
仅查看它,它看起来是在文件中添加方括号和逗号的简单情况,但实际上,每个虚拟用户都试图附加相同的文件,而我正在努力地以某种方式设置其格式方括号不会再次使用,只能使用一次。
所以我不要:
[“ 3a917e22-3c76-45de-a104-4e2aa4b72a35”],
[“ 929c89c0-7a1a-4a18-8ee8-2958c9cd430f”]
答案 0 :(得分:0)
基本使用before after
的加特林机钩子和一些印刷机魔术师
这是我的代码:
try {
val br = new BufferedReader(new FileReader(deleteGuidsFilePath))
var last : String = ""
var line = br.readLine
while ({line != null})
{
last = line
line = br.readLine
}
br.close()
afterPw.write(last.replace(",", "]"))
afterPw.close()
}
catch {
case e: Throwable => println("Couldn't read the file")
}