如何使用 JMeter 将 API 标记存储在变量中
How to store an API token in a variable using JMeter
我是 Jmeter 的新手,刚开始使用它。我有一个场景,下面是输入的详细信息。
场景:
- 使用微软凭据登录应用程序(API No.1)
- 导航到客户搜索页面
- Select 值说搜索'By name'(按名称是API No.2)
- 点击搜索
- 将显示结果
第 1 步 API 我能够成功完成,因为我关注了互联网上的一些视频。
但是对于与 API(按名称)相关的应用程序,我能够为当前 session 执行此操作,但不能为所有 session.
执行此操作
按名称 API 我将 'HTTP Request' 的 'Body Data' 传递为
{"branch":null,"agent":{"code":"00092","type":null,"name":"SOVQOSTOVJT OSJOTWW","unit":{"code":" A0102","name":"OJTVWXSKSVVKJ JVSXVJXS","unitHead":null},"branch":{"code":"A0100","name":"SXTJV","channel":null},"rank" :{"code":"BM","description":"高级总监"},"emailAddress":"mt_mls_bm1@mlsg.onmicrosoft.com","status":{"code":"01" "description":"Active"},"candidate":{"number":"14000350","name":"SOVQOSTOVJT OSJOTWW","dob":"1956-04-25"},"originalAgentCode":" 000092"},"searchBy":"P","nameSearchParam":{"customerName":null,"idNo":null},"policySearchParam":{"policyNo":"14708787"},"policyStatusSearchParam":{" policyStatus":null,"startDate":null,"endDate":null,"daysLeftBeforeExpiry":null},"policyByServiceTrackingSearchParam":{"customerName":null,"policyNo":null,"idNo":null,"customerStatus" :null,"recievedDateBST":{"begin":"2021-06-26T","end":"2021-08-26T"}},"policyByPremiumSearchParam":{},"policyByUnsuccess":{},"unit ":null}
HTTP Header 管理员
JSON 提取器
问题是,如果您看到 2 个标记值 'manutouch_token' 和 'X-Auth-Token',这些都是动态值。当我在当前 session 这将具有这些值,注销后将生成新值。我想将这些令牌值存储在某个地方并传递它,或者需要提取令牌的某些部分。我不知道如何做这个过程。我一点也不知道。谁能帮帮我。
很可能这些令牌在登录过程中的某处返回,您需要仔细检查所有响应(注意字面上的所有内容:响应主体,response headers, response URL especially in case of redirection)- 令牌应该在那里。
一旦你弄清楚它们住在哪里,你应该能够使用合适的 Post-Processors, well configured Post-Processor will extract the token from the response and store it into a JMeter Variable 提取它们,你将能够用包含实际标记的动态变量替换记录的值。
请参阅 Using Regular Expressions to Extract Tokens and Session IDs to Variables article for example implementation (use it as a reference only, not as the guide as your application details might be different), the key point is implementing the correlation 了解测试场景中的每个动态参数
我是 Jmeter 的新手,刚开始使用它。我有一个场景,下面是输入的详细信息。
场景:
- 使用微软凭据登录应用程序(API No.1)
- 导航到客户搜索页面
- Select 值说搜索'By name'(按名称是API No.2)
- 点击搜索
- 将显示结果
第 1 步 API 我能够成功完成,因为我关注了互联网上的一些视频。 但是对于与 API(按名称)相关的应用程序,我能够为当前 session 执行此操作,但不能为所有 session.
执行此操作按名称 API 我将 'HTTP Request' 的 'Body Data' 传递为
{"branch":null,"agent":{"code":"00092","type":null,"name":"SOVQOSTOVJT OSJOTWW","unit":{"code":" A0102","name":"OJTVWXSKSVVKJ JVSXVJXS","unitHead":null},"branch":{"code":"A0100","name":"SXTJV","channel":null},"rank" :{"code":"BM","description":"高级总监"},"emailAddress":"mt_mls_bm1@mlsg.onmicrosoft.com","status":{"code":"01" "description":"Active"},"candidate":{"number":"14000350","name":"SOVQOSTOVJT OSJOTWW","dob":"1956-04-25"},"originalAgentCode":" 000092"},"searchBy":"P","nameSearchParam":{"customerName":null,"idNo":null},"policySearchParam":{"policyNo":"14708787"},"policyStatusSearchParam":{" policyStatus":null,"startDate":null,"endDate":null,"daysLeftBeforeExpiry":null},"policyByServiceTrackingSearchParam":{"customerName":null,"policyNo":null,"idNo":null,"customerStatus" :null,"recievedDateBST":{"begin":"2021-06-26T","end":"2021-08-26T"}},"policyByPremiumSearchParam":{},"policyByUnsuccess":{},"unit ":null}
HTTP Header 管理员
JSON 提取器
问题是,如果您看到 2 个标记值 'manutouch_token' 和 'X-Auth-Token',这些都是动态值。当我在当前 session 这将具有这些值,注销后将生成新值。我想将这些令牌值存储在某个地方并传递它,或者需要提取令牌的某些部分。我不知道如何做这个过程。我一点也不知道。谁能帮帮我。
很可能这些令牌在登录过程中的某处返回,您需要仔细检查所有响应(注意字面上的所有内容:响应主体,response headers, response URL especially in case of redirection)- 令牌应该在那里。
一旦你弄清楚它们住在哪里,你应该能够使用合适的 Post-Processors, well configured Post-Processor will extract the token from the response and store it into a JMeter Variable 提取它们,你将能够用包含实际标记的动态变量替换记录的值。
请参阅 Using Regular Expressions to Extract Tokens and Session IDs to Variables article for example implementation (use it as a reference only, not as the guide as your application details might be different), the key point is implementing the correlation 了解测试场景中的每个动态参数