Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Jmeter uses BeanShell for association

Shulou Source: shulou.com Published: 2022-06-03 05:13:20 09月16日 Update

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.

Tags: Regular information code parameters associations examples content variables files parts processing login functions can be passed commands large numbers documents sometimes steps source code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL macOS MariaDB Shulou Tech Info