Interface test Tool-jmeter using notes (ix: Passing variables across thread groups)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.