In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how Jmeter through the OS process sampler call Python script to achieve parameter transfer, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let Xiaobian with you to understand.
1. The usage explanation of sys.argv in Python: sys.argv allows python scripts to obtain parameters from outside the program. Sys.argv is a list in which elements can be extracted with []. The first element is the program itself, followed by external parameters. Multiple parameters can be accepted, and each parameter can be separated by a space.
Import hashlibimport sysimport time parameter = sys.argv# print (parameter, type (parameter)) def password_srt (pubkey, password): time_str = str (time.time ()) sign_str = pubkey + time_str + password sign = hashlib.md5 (sign_str.encode ('utf-8'). Hexdigest () res = {' sign': sign, 'pubkey': pubkey) The content of 'password': password} # print () can be received by jmeter The relevant parameters can be extracted in jmeter. Print (res) return res if _ _ name__ ='_ _ main__': password_srt (parameter [1], parameter [2])
For example, call the above Python script in cmd and pass in two parameters:
Note: the contents of print () in the script can be received by jmeter, and the relevant parameters can be extracted using the regular expression extractor in jmeter.
2. Add a .bat file, specific command content: python E:\ python_project\ Python-Auto\ python_jmeter\ jmeter_os_process.py% 1% 2 [% 1% 2 means passing 2 parameters to the python file (or using% 1% 1 also means passing two parameters)].
3. Reading batch files through the OS Process Sampler component of JMeter is actually executing the python script written.
(1) add [OS process Sampler] to jmeter through the following path:
(2) ① enter the path to the .bat file in the [Command] input box, for example: e:\ python_project\ Python-Auto\ python_jmeter\ jmeter_os_process.bat
② adds [values] to [Command Line parameters]. According to the values passed here, the .bat file needs to enter several values, such as% 1% 2 for two.
For ③ [command line arguments] to add [value], you can use variables, such as variables that refer to jmeter parameterization.
4. Use the regular expression extractor to extract the parameters printed in the python script for jmeter to use. (a regular expression extractor can extract only one parameter, and multiple extractors can be used to extract multiple parameters.)
5. For example, use the extracted parameters in the API request:
Thank you for reading this article carefully. I hope the article "how Jmeter calls the Python script through the OS process sampler to transfer parameters to each other" is helpful to everyone. At the same time, I also hope you can support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.