文章主要介绍gatling测试过程中遇到上一个request返回参数,需要经过调用第三方jar包方法签名后再传递至第二个request中作为参数,发起请求。
调用第三方jar包需要用到gatling工具中session方法,具体请参考代码:
import com.xxx.Getkey
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.core.structure._
class verifyData extends Simulation {
//设置请求的根路径
val httpConf = http
.baseURL("https://xx.xx.xxx.xx:xxxx")
val headers_json = Map("Content-Type" -> "application/json")
def getkey= new Getkey()
val Key = "1234567890"
val scn = scenario("verifyData")
.exec(
http("getData")
.get("/getData")
.headers(headers_json)
.check(status.is(200))
.check(jsonPath("$.challengeStr").saveAs("challengeStr"))
.check(jsonPath("$.index").saveAs("index")))
.exec(session => {
val challengeStr = session("challengeStr").as[String]
val result = getkey.getKeys(Key, challengeStr)
session
})
.exec(
http("verifyData")
.post("/verifyData")
.headers(headers_json)
.body(StringBody("""{"index":"${index}","signature":"result"}""")).asJSON
.check(status.is(200)))
//设置线程数
setUp(scn.inject(atOnceUsers(1)).protocols(httpConf))
}