Usage scenarios:
The request API requires an authorization token, but the authorization token needs to be fetched only once to invoke other business interfaces on the server.
So I want to put the authorization action on a separate thread, and the business is banished to the other threads.
This will require me to pass the token obtained from the authorization thread into the orchestration.
Workaround ——— Post Processor BeanShell preprocessor
1. First select the "Get token" thread Group: Add a regular expression to extract the token value (do not use regular expression of the classmate please consult the blogger before jmeter related articles)
2. In the "Get Token" thread Group: Add the Post processor BeanShell Postprocessor
Parameters: Reference to the variable extracted by the regular expression ${token}
Script: Specific BeanShell syntax you can go to see the relevant information, here is very simple, a statement will be done.
This means that the obtained variable ${token} is set to a global variable and referenced with the new name Newtoken.
3. In the "Business Flow" thread Group, refer to the global variable Newtoken
The reference is ${__p (Newtoken,)}, note that the curly braces are two underscores, followed by a comma after Newtoken, do not write leaks.
As for the fixed timer that I add to this thread group, it is because if the timer is not added, the two threads are executed synchronously, and the token value has not obtained the interface request to make the business flow, which causes the request to return the failure.
4. Execution, view results
The token value obtained is shown in the
Citation successful ~
Interface test Tool-jmeter using notes (ix: Passing variables across thread groups)