简体   繁体   English

Jmeter - 如何将多个令牌从 http 登录请求传递到另一个 http 请求

[英]Jmeter - How to pass multiple tokens from http login request to another http request

I am currently designing a test case for multiple users testing using jmeter and I kind of need some help.我目前正在为使用 jmeter 的多个用户测试设计一个测试用例,我需要一些帮助。 Here's the scenario: Suppose I have 2 different login portals with 500 different users on each portal.场景如下:假设我有 2 个不同的登录门户,每个门户上有 500 个不同的用户。 I want to do login, access getExamSchedule, startExam, getListQuestion, getOneQuestion, submitOneQuestion and finishExam so I create one new thread group for each request.我想登录、访问 getExamSchedule、startExam、getListQuestion、getOneQuestion、submitOneQuestion 和 finishExam,因此我为每个请求创建了一个新的线程组。 Each thread has 2 samplers (1 for portal A, 2 for portal B).每个线程有 2 个采样器(1 个用于入口 A,2 个用于入口 B)。 My question is how am I supposed to pass the multiple generated tokens from login thread so that I can access the rest of the thread with different tokens.我的问题是我应该如何从登录线程传递多个生成的令牌,以便我可以使用不同的令牌访问线程的 rest。 And also each http request has some response I need to extract to be used on another thread.而且每个 http 请求都有一些我需要提取的响应以用于另一个线程。 I tried to extract the tokens and the responses to csv file but somehow it didn't work.我试图提取令牌和对 csv 文件的响应,但不知何故它不起作用。 Let me know if there's any best practice for this scenario.让我知道这种情况下是否有任何最佳实践。 Thank you in advance!先感谢您! jmeter 脚本

so I create one new thread group for each request - normally you should create separate/different Thread Groups only for new logical groups of virtual users, for your use case I think everything could be in one Thread Group. so I create one new thread group for each request ——通常你应该只为虚拟用户的新逻辑组创建单独的/不同的线程组,对于你的用例,我认为一切都可以在一个线程组中。

As per JMeter Documentation :根据JMeter 文档

Properties are not the same as variables.属性与变量不同。 Variables are local to a thread ;变量是线程的局部变量 properties are common to all threads, and need to be referenced using the __P or __property function.属性对所有线程都是通用的,需要使用 __P 或 __property function 进行引用。

So if you really need to pass values across different Thread Groups - you can take a look at following solutions:因此,如果您确实需要跨不同的线程组传递值 - 您可以查看以下解决方案:

  1. __setProperty() ,__threadNum() and __P() functions combination like: __setProperty()__threadNum()__P() 函数组合如下:

    • To set the property:设置属性:

       ${__setProperty(token_${__threadNum},${jmeter-variable-holding-the-token},)}
    • To read the property: ${__P(token_${__threadNum},)}读取属性: ${__P(token_${__threadNum},)}

  2. Use Inter-Thread Communication Plugin使用线程间通信插件

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM