简体   繁体   English

加特林:上一个请求没有JSON响应时,如何在下一个请求中传递值?

[英]Gatling: How to pass value in next request when previous request doesn't have JSON response?

Please consider the scenario... Here, in GET request I found 'derId' but it's response is not JSON. 请考虑这种情况...在这里,在GET请求中我找到了'derId',但它的响应不是JSON。 So I am not able to save this value in that request. 因此,我无法在该请求中保存此值。

    .exec(http("OnClick")
        .get("/url/apz?action_id=1&SelectRadiobutton=1_${abcID}_${xyzID}_${zipID}")
        .headers(headers_1))
    .pause(2)
    .exec(http("PopUp")
        .post("/url/dis")
        .headers(headers_1)
        .formParam("action_id", "2")
        .formParam("abcId", "${abcID}")
        .formParam("rmft", "${rmftID}")
        .formParam("msg_id", "${msgID}")
        .formParam("matId", "${matID}"))
    .pause(1)
    .exec(http("Bananana")
        .post("/url/abc")
        .headers(headers_1)
        .formParam("abcId", "${abcID}")
        .formParam("msg_id", "${msgID}")
        .formParam("matId", "${matID}")
        .formParam("derId", "${??}"))

Is there any method or way to pass the value in next request from GET request??? 有什么方法或方法可以在GET请求的下一个请求中传递值???

Or 要么

How to save a value, when a request doesn't have JSON response??? 当请求没有JSON响应时,如何保存值?

Can a GET request have JSON response??? GET请求可以具有JSON响应吗???

Your help will be much appreciated. 您的帮助将不胜感激。

Thanks! 谢谢!

By using regex method, we can save values from jsp page (not json). 通过使用regex方法,我们可以保存jsp页面(而不是json)中的值。

for example: 例如:

.check(regex("""type="hidden" name="abcId" id="abcId" value="([\w=\/.\d_%+-.$]*)"""").saveAs("abcID"))

Thanks! 谢谢!

I was able to use this answer ( https://stackoverflow.com/a/40736282/9371636 ) from a similar question to make a request, then another request with an input parameter that came from the JSON response of the first request. 我能够使用类似问题中的这个答案( https://stackoverflow.com/a/40736282/9371636 )发出请求,然后发出另一个输入参数来自第一个请求的JSON响应的请求。

Example API I'm testing with: 我正在测试的示例API:

/step1 -> returns { "key": 888 }
/step2/{key} -> returns { "key": 999 } if {key} passed in is == 888

Scala Code: Scala代码:

var step1 = exec(http("step1")
    .get("/step1")
    .check(jsonPath("$..key").optional.saveAs("key")))

var step2 = exec(http("step2")
    .get("/step2/${key}"))

val scn: ScenarioBuilder = scenario("SimulationName").exec(step1,
    doIf(session => session.contains("key")) {
        exec(step2)
    })

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在加特林脚本的下一个请求中传递相关值 - How to pass correlated value in next request in Gatling script 如何将响应正文字段传递给其他请求的正文(加特林) - How to pass response body field to other request's body (Gatling) 在 Gatling / Scala 中循环来自先前请求的多个响应匹配 - Loop over multiple response matches from previous request in Gatling / Scala 如何在加特林报告中查看请求和响应 - How to view request and response in Gatling report 如何将值列表传递给加特林请求 - How to pass a list of values to gatling request 如何从 cookie 中保存 XSRF 令牌并将其传递到 Gatling 的下一个请求标头中的服务器 - How can save XSRF token from cookie and pass it to server in next request header in Gatling 如何解析动态json响应并获取特定值并将其作为输入传递给下一个请求 - How to parse dynamic json reponse and get specific value and pass it as an input to next request 如何将具有嵌套结构的 Gatling jsonFeeder 转换为 json 请求正文? - How to convert a Gatling jsonFeeder with nested structures to json request body? 在加特林中将请求的响应字符串解析为另一个方法 - Parse the response string of a request into another method in gatling 如何忽略加特林中失败的请求 - How to ignore the failed request in Gatling
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM