简体   繁体   English

编写一个简单的JMeter脚本

[英]Writing a simple JMeter script

I need to write a script that does the following (doesn't matter to which website, I am only doing this to learn and practice): 我需要编写一个执行以下操作的脚本(与哪个网站无关,我只是这样做才能学习和练习):

  1. Simulates HTTP requests (method: get) 模拟HTTP请求(方法:get)
  2. Reads parameters from a document and uses them in the script 从文档中读取参数并在脚本中使用它们
  3. Saves an expression from the response of the request and uses it as a parameter in the next request 保存请求响应中的表达式,并将其用作下一个请求中的参数
  4. Saves the output to a file 将输出保存到文件

After a few hours of reading the documentation and watching some video tutorials, I can manage step 1 easily. 在阅读文档并观看一些视频教程几个小时之后,我可以轻松地管理第1步。 I have a little idea on how to do steps 2 and 4 though there might be a chance that I am not doing them efficiently. 我对如何进行第2步和第4步有一点了解,尽管我可能不会有效地执行它们。 And unfortunately I have no idea how to do step 3. 不幸的是,我不知道如何做第3步。

Can someone help me in doing those steps please or at least give me some good links to tutorials that may help me out (I've found the official manual too confusing)? 有人可以帮我做这些步骤,或者至少给我一些很好的链接,可以帮助我解决教程(我发现官方手册太混乱了)?

Here are some links I used to learn this tool: For step 1 and for step 2 they helped a little but more guidance is welcomed. 以下是我用来学习这个工具的一些链接: 对于步骤1步骤2,他们帮助了一点,但欢迎更多的指导。

The best sources of Jmeter documentation I know about are in Documentation section at JMeter website: user manual and best practices (for starters), Component Reference and Functions reference (once you are comfortable with basic Jmeter capabilities). 我所知道的Jmeter文档的最佳来源是JMeter网站的文档部分: 用户手册最佳实践 (适用于初学者), 组件参考功能参考 (一旦您熟悉基本的Jmeter功能)。

Especially you should read 4th , 5th and 6th sections of User Manual that will give you answers to those and many other questions that you'll have. 特别是你应该阅读用户手册的 4第5第6部分,它们将为你提供答案以及你将拥有的许多其他问题。

Nevertheless I should give answers by myself: 不过我应该自己给出答案:

  1. Use HTTP Request Sampler 使用HTTP请求采样器
  2. Use CSV Data Set Config 使用CSV数据集配置
  3. Use PostProcessor. 使用PostProcessor。 I guess the most helpful will be Regular Expression Extractor that will extract data to variable and then you can use this variable as ${variable} in your test 我想最有用的是正则表达式提取器,它将数据提取到变量,然后你可以在测试中将此变量用作${variable}
  4. I guess you mean test results by output. 我想你的意思是输出的测试结果。 If this is case, use Listeners. 如果是这种情况,请使用监听器。 In my experience the most helpful listeners are Simple Data Writer, View Results Tree (only for debugging), Response Latencies over Time from Jmeter plugins. 根据我的经验,最有用的监听器是简单数据写入器,查看结果树(仅用于调试),Jmeter插件随时间的响应延迟 Note that only Simple Data Writer should be enabled when you'll eventually run your test against SUT to minimize resources usage. 请注意,当您最终针对SUT运行测试以最小化资源使用时,应仅启用Simple Data Writer。

Once you are comfortable with JMeter capabilities note that some useful functionality is absent in it but exists in JMeter plugins : 一旦您熟悉JMeter功能,请注意其中没有一些有用的功能,但存在于JMeter插件中

Use post processors like Regular expression extractors , JSON extractors to extract any values. 使用正则表达式提取器,JSON提取器等后处理器来提取任何值。

Add These post processors as a child of http samplers and name,enter regular expression , template ... 将这些后期处理器添加为http采样器和名称的子项,输入正则表达式,模板...

http://regex101.com/ is the best site to test your regular expressions http://regex101.com/是测试正则表达式的最佳网站

To use the extracted value futher in your script use ${variable_name} 要在脚本中使用提取的值,请使用$ {variable_name}

For more info please read this article 欲了解更多信息,请阅读这篇文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM