如何在没有任何插件的情况下在非 GUI 模式下在一个实例上运行多个 .jmx 录制的脚本?

问题描述 投票:0回答:3

我正在使用 JMeter 对我的 Web 应用程序进行性能测试。

我尝试通过将所有脚本合并为一个来运行多个(超过 1 个).jmx,但它在 Jmeter 非 GUI 模式下不起作用。那么是否可以在不使用 Maven 或 Ant 插件等任何插件的情况下从 Jmeter 非 GUI 模式运行多个 .jmx 录制的脚本?请记住,所有不同的脚本都有不同的凭据来登录 Web 应用程序并执行不同的任务。

提前谢谢您。

jmeter
3个回答
0
投票

说明将根据您的操作系统而有所不同:

  • 对于基于 Unix 的(LinuxMacOSXFreeBSD 等):您可以使用

    GNU parallel
    程序:

    parallel --gnu << 'EOF'
    jmeter -n -t test1.jmx -l result1.jtl
    jmeter -n -t test1.jmx -l result2.jtl
    etc.
    EOF
    
  • 对于 MS Windows:您可以使用 CMD 或 Powershell 脚本,假设

    start
    命令类似于:

    start jmeter -n -t test1.jmx -l result1.jtl
    start jmeter -n -t test2.jmx -l result2.jtl
    etc.  
    

最快、最简单的方法是使用 Taurus 工具,您将能够通过简单的 YAML 语法同时启动不同的 JMeter 测试:

---
execution:
- scenario:
    script: test1.jmx
- scenario: 
    script: test2.jmx
- scenario: 
    script: test3.jmx
    #etc

请参阅Taurus - 使用多个 JMeter 测试了解更多详细信息。


0
投票

您可以根据您的要求在单个 .jmx 中按顺序或并行运行多个线程组。 欲了解更多信息,请查看这个

希望这有帮助。


0
投票

如果您在Mac上运行它,您可以创建一个.sh文件(即scripts.sh)并将以下命令粘贴到其中:

#!/bin/bash

# Define the directory containing the JMX files
JMX_DIR="/path/to/jmx/files"

# Loop through each JMX file in the directory
for jmx_file in "$JMX_DIR"/*.jmx; do
  # Execute the JMX file with JMeter
  echo "Executing: $jmx_file"
  sh jmeter -n -t "$jmx_file" -l "${jmx_file%.jmx}.jtl" -e -o "${jmx_file%.jmx}.html"
done

完成后,将此文件放入 apache-jmeter 的 /bin 目录中,并在终端中运行以下命令:

# to make the script
chmod +x scripts.sh

# to run the script
./scripts.sh

这样它将选择所有 jmx 文件,并且不需要手动一一列出所有脚本。此外,它还会为每个脚本生成 HTML 报告。

© www.soinside.com 2019 - 2024. All rights reserved.