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

[new Dream sharing] Jmeter skills: how to set variables in Json data

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

Share

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

I have two interfaces, interface An and interface B, and interface B is as follows:

The question is how to set the value after name in {"tag": {"name": "123456"}} as a variable, which is extracted from interface A.

If you use regular expressions or json extractors, such as:

The extracted value is directly used in API B, for example: {"tag": {"name": "${tokens}"}, and the final return value will be {"tag": {"id": 149, "name": "${tokens}"}}.

Solution: data in json format can store two forms of variables (as far as I know). One is a function in the function helper, such as:

The other is to read external files from the outside world and put them into data in json format, such as:

The rest is very simple. Now that you know how to put the data in json format, all that is left is how to extract the data from the first interface and put it in a file. Here is an example:

First, we add a pre-processor BeanShell PreProcessor or post-processor BeanShell PostProcess, and write a script in it, as shown in the following code:

FileWriter fw = new FileWriter ("E:\\ tokens.csv", false)

BufferedWriter bw = new BufferedWriter (fw)

Bw.write (vars.get ("tokens") + "\ n")

Bw.close ()

Fw.close ()

Now the local E: this path under the new tokens.csv file, false represents the next overwrite last time, if you write true, on behalf of the append, after the new file, new a bufferedWriter object, vars.get means to get the first interface with regular expressions to extract the data tokens, and then write to the file, and then close these two methods, be sure to write close.

A general process is that the regular expression extracts the data, the processor stores the extracted data in the specified file, and configures the original CSV data file to set the data in the file as variables into the data in json format.

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