模块化 JMeter 测试?
我们希望将我们的测试框架迁移到 JMeter。我们有 50 多个测试用例,每个测试用例都有重复的操作,例如登录和注销。如何模块化我的方法?
我正在寻找的具体内容是“从文件添加测试项目”,以便我可以添加登录代码。
我们还有诸如 ConnectionID 之类的东西,需要在每个请求上传递。 jMeter 是否可以自动用 Jmeter 变量替换所有出现的地方? Atm 代理记录器记录实际的连接字符串,我们必须手动将其替换为 ${connectionID}。有更好的办法吗?
We are looking to migrate our testing framework over to JMeter. We have 50 + test cases, each of them with repeating actions like Logging in and logging out for example. How can I modularize my approach?
What I'm looking for specifically is a "Add test item from file" so that I could for example, add the login code.
We also have things like connectionID's that need to be passed on every request. Is there anyway jMeter can AUTOMATICALLY replace all occurrences of it with a Jmeter variable? Atm the proxy-recorder records the actual connection string, and we have to manually replace that with ${connectionID}. Is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
这对我来说效果很好。
在测试计划的底部创建一个新的线程组,并在其中放置一个简单的控制器。在简单控制器内放入您想要重复的代码。我使用两个简单的控制器,但其中一个实际上是数据库测试用例套件。在保持线程组内的任何内容处于启用状态的同时,请确保将线程组本身设置为禁用状态,否则它将再次自行执行。
现在,在任何特定的测试用例中,添加用户参数并添加模块控制器。模块控制器可以指向您之前制作的简单控制器部分。让简单的控制器设置了 ${variables} ,然后通过将变量放入用户参数中来在您正在运行的特定测试中覆盖它们。因此,您可以使用同一套件获得不同的变量和测试。
我在简单控制器中放置了一个简单控制器来添加冗长的数据库测试。最终结果为
Thread Group >简单控制器>简单控制器> JDBC 请求。全部都改名了。
您可以在测试内的模块控制器中选择不同的。我现在大约有六个,但这已经重复了几十次。
这一切都与库存 Jmeter 2.3 相关。如果您处于无法安装插件的环境中,这也可以正常工作。我从来没有尝试过它们
HTH
This works fine for me.
Make a new thread group at the bottom of the test plan and put a simple controller in it. Inside the simple controller put the code you want to repeat. I use two simple controllers but one is actually a DB test case suite. While keeping whatever is inside the thread group enabled, make sure to put the thread group itself as disabled, or else it will execute again on its own.
Now, in any particular test case, add User Parameters and add a Module Controller. The Module Controller can point to the simple controller section(s) you made before. Have the simple controller with a ${variables} set, then override them here inside the particular test you are running by putting the variable in the User Parameters. Thus you get the different variables and tests with the same suite.
I put a Simple Controller inside the Simple Controller to add lengthy db tests. This ends up as
Thread Group > Simple Controller > Simple Controller > JDBC Request. All are renamed.
You can select different ones in the Module Controller inside the tests. I have about six right now but this gets repeated dozens of times.
This is all with a stock Jmeter 2.3 . If you are in an environment such that you can't install the plugins, this will work fine. I've never tried them
HTH
据我所知,没有办法通过 GUI 自动替换连接 ID。然而,测试脚本是简单的 XML 文件,因此编写 sed 或 awk 脚本来为您进行替换将非常容易。
至于“从这里添加测试文件”部分,在2.6中(不确定其他版本,没有使用它们)有一个名为“Include Controller”的逻辑控制器,可以加载测试片段。还有保存片段的功能将称为“测试片段”的测试代码添加到它们自己的 .jmx 文件中。
如果您开始一个新的测试计划,请右键单击测试计划,然后添加 ->测试片段->测试片段,这将添加容器,然后您可以添加其他请求并在上述 Include 元素中使用此块。
如果您能够使用最新版本,或者之前的版本支持此功能,那么这可能是比编写自己的插件更简单的选择。
As far as automatically replacing the connection IDs, there is not, to my knowledge, a way to do that via the GUI. However, the test scripts are simple XML files and so it would be very easy to write a sed or awk script to do that replacement for you.
As far as the "add test file from here" part, in 2.6 (not sure about other versions, not used them) there is a logic controller called "Include Controller" that can load test snippets.There is also the ability to save snippets of test code called "test fragments" to their own .jmx files.
If you start a new test plan, right click on test plan then add -> test fragment -> test fragment this will add the container, then you can add your other requests in and use this chunk inside the aforementioned Include element.
If you are able to use the latest version, or if the prior versions support this, this may be a simpler option than writing your own plugin.
通过使用下面的 Jmeter 元素,我们可以模块化测试脚本。
请检查此以获取更多详细信息和信息。例子。
http://www.testautomationguru.com/jmeter-modularizing-test-scripts/
By using below Jmeter elements, we can modularize the test scripts.
Please check this for more details & examples.
http://www.testautomationguru.com/jmeter-modularizing-test-scripts/
我知道你有 2 个选择:
I know 2 options for you:
听起来您可能想将一些重复的逻辑封装在您自己的自定义采样器或配置元素中。在项目页面上有一个向 JMeter 编写插件的指南。
这是我们当前团队采用的方法,用于处理 JMeter 模拟自定义 RPC 格式的请求。
Sounds like you might want to encapsulate some of that repeated logic in your own custom Samplers or Config Elements. There is a guide to writing plugins to JMeter on the project page.
This is the approach that we have taken on my current team for handling JMeter simulating requests of a custom RPC format.
一件事是您可以在“noGUI”模型下运行 jmeter 脚本。您可以指定要运行的 jmeter 测试脚本并将一批测试脚本放入 .bat 文件中。喜欢:
我同意@matt的另一种方式是你可以编写插件来满足你的需要。
One thing is you can run the jmeter scripts under "noGUI" model. You can specify the jmeter test scripts to run and put a batch of them into a .bat file. Like:
Another way I agree with @matt is you can write the plugin to get what your need.