【问题标题】:Is it possible to replace a part of value from captured correlation in Loadrunner?是否可以从 Loadrunner 中捕获的相关性中替换部分价值?
【发布时间】:2020-12-02 19:34:42
【问题描述】:

我正在关联 json 响应,但从捕获的 json 中,我需要用一些不同的文本替换一个值。 例如 - 捕获的响应如下并保存到“corr_json”变量:

{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": JSON:API paints my bikeshed!,
      "body": "The shortest article. Ever.",
      "created": "2015-05-22T14:56:29.000Z",
      "updated": "2015-05-22T14:56:28.000Z"
    },
    "relationships": {
      "author": {
        "data": {"id": "42", "type": "people"}
      }
    }

从此我需要替换字符串 API paints my bikeshed 带有文本Performance Testing 并传递给下一个请求,因此要传递的json如下:

{
  "data": [{
    "type": "articles",
    "id": "1",
    "attributes": {
      "title": "Performance Testing",
      "body": "The shortest article. Ever.",
      "created": "2015-05-22T14:56:29.000Z",
      "updated": "2015-05-22T14:56:28.000Z"
    },
    "relationships": {
      "author": {
        "data": {"id": "42", "type": "people"}
      }
    }

有没有办法在 Loadrunner 中做到这一点?

【问题讨论】:

    标签: performance-testing loadrunner vugen


    【解决方案1】:

    查看LoadRunner提供的lr_json_replaceapi。

    【讨论】:

      【解决方案2】:

      根据您使用的协议,LoadRunner 的语言可以是 C、C#、C++、VB 或 JavaScript。使用您的语言的字符串处理功能,结合您的编程技能,重新格式化相关文本以包含您的标签。

      提示,您可能会考虑返回数据的两个相关性,一个以第一个花括号开头并以 '"title":' 结尾,第二个以 '"title":' 开头并以 '\t 结尾\t}\r\t}' (如果我正在阅读正确的文本)结构。然后您可以简单地在 C 中使用 sprintf() 将几个字符串(corr1+ 您的 tag+corr2+ 末端结构)打包在一起以达到您的目标。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多