Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Jmeter uses BeanShell for association

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

The so-called relevance, the number is to grab part of the information through the corresponding information, such as hidden or session and so on.

To use associations in jmeter, there are two steps:

Step 1. Add a regular expression under the Sampler request to get the information, Add > Post Processors > Regular Expression Extractor

1.1 most of us need to intercept part of the information. We can look at the source code, find the code we need, and then use regular processing. Here is an example:

The function is to extract values from userSession

1.2 sometimes, when we need to extract all the response information, we can use the following rules:

Step2. Add PostProcessers, select BeanShell PostProcessor, and then go further.

In BeanShell, we can use java code to deal with the regular extraction. The general step is to receive the value extracted by the regular expression. If this value needs to be used as a parameter for later Sampler, we have to save it as a variable to facilitate later call.

Continue to illustrate with userSession in the first example:

Since the post needs to submit the session in the login url, I saved it as the variable Session. Here is the session value of the call to the login url.

If we need to print the regular crawl to the local document, we can add the following code to BeanShell PostProcesser:

Import java.io.*

String value = bsh.args [0]

Print (value)

File f = new File ("D:" + File.separator+ "log.txt")

FileWriter w = new FileWriter (fjre true)

W.write (value+ "\ n")

W.close ()

Value receives parameter values, print prints the parameters to the command line, and I use D:\ log.txt for the local file, which can be set by myself. Save to a file, which can be used to analyze statistics.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report