![](/img/trans.png)
[英]How can I get Header Response using HTTP Proxy Recording from Gatling
[英]Put condition in HTTP request using gatling
我想在http請求上添加條件。 在這種情況下,使用API
我在找到“操作ID”的地方有一個操作
使用該“動作ID”,我檢查該動作的狀態為“正在運行/正在等待/已完成/等”,並將其保存在變量中
我做了這兩個步驟,現在我想做
3.如果狀態為“正在運行”,我必須每20分鍾檢查一次狀態,如果狀態=“已完成”,則每20分鍾重新檢查一次狀態,然后在2小時后自動退出oR退出(即使狀態為運行狀態)
編輯:想把這樣的條件,
Check status = true
{
pause for 15minutes
request once again after 15minutes
if(status = false)
{
exit
}
else
{
request once again and check status, if true wait for 15minutes
If total waiting time is more than 2 hours then exit
}
}
else
{
exit
}
下面是我的代碼片段
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import scala.concurrent.duration._
class LaunchResources extends Simulation {
val scenarioRepeatCount = Integer.getInteger("scenarioRepeatCount", 1).toInt
val userCount = Integer.getInteger("userCount", 1).toInt
val UUID = System.getProperty("UUID", "24d0e03")
val username = System.getProperty("username", "p1")
val password = System.getProperty("password", "P12")
val testServerUrl = System.getProperty("testServerUrl", "https://someurl.net")
val httpProtocol = http
.baseURL(testServerUrl)
.basicAuth(username, password)
.connection("""keep-alive""")
.contentTypeHeader("""application/vnd+json""")
val headers_0 = Map(
"""Cache-Control""" -> """no-cache""",
"""Origin""" -> """chrome-extension://fdmmgasdw1dojojpjoooidkmcomcm""")
val scn = scenario("LaunchAction")
.repeat (scenarioRepeatCount) {
exec(http("LaunchAResources")
.post( """/api/actions""")
.headers(headers_0)
.body(StringBody(s"""{"UUID": "$UUID", "stringVariables" : {"externalFilePath" : "/Test.mp4"}}"""))
.check(jsonPath("$.id").saveAs("WorkflowID")))
.exec(http("SaveWorkflowStatus")
.get("""/api/actions/{$wflowid}""")
.headers(headers_0)
.check(jsonPath("$.status").saveAs("WorkflowStatus")))
.asLongAs(session => session.attributes("WorkflowStatus") != false) {
pause(900)
.exec(http("SaveWorkflowStatus")
.get("""/api/actions/${WorkflowID}""")
.headers(headers_0)
.check(jsonPath("$.running").saveAs("WorkflowStatus")))
}
}
setUp(scn.inject(atOnceUsers(userCount))).protocols(httpProtocol)
}
請幫忙。 謝謝
試試這個asLongAs(session => session.attributes(response) != "MY STATUS") { exec( http().get(). .check(xpath("//status").saveAs(response) ) }
所以基本上這樣可以一直運行直到響應值不等於我的狀態。
您還可以在asLongAs中添加其他短路條件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.