更改Jmeter的执行顺序并在配置之前运行预处理器,或将环境变量用于CSV数据集配置的FilePath

时间:2019-06-26 08:07:48

标签: maven jmeter

我正在读取CSV文件的内容以传递给我的HTTP请求,我可以正确地执行此操作,但是问题是来自CSV文件的路径(来回读取)在环境变量之一中。 我尝试使用JSR223预处理器读取环境变量并将路径设置为属性,然后在FilePath字段中使用属性值, 但是由于JMeter元素的执行顺序,即使我将它们放置在SetUp线程中,Congif元素也会在预处理器之前执行。

我是Jmeter测试的新手。寻找有人帮助如何更改执行顺序(如果可能)以在预处理器之后运行Config元素,或者如何将Environment变量直接获取到CSV DataSet Config的FilePath字段中?

我尝试使用安装程序线程进行预处理,然后使用下一个线程来运行配置,但它不起作用。

1 个答案:

答案 0 :(得分:0)

您可以使用__P() function来参数化CSV文件的路径,例如:

enter image description here

完成后,您应该可以通过-J command-line argument设置属性值,例如:

  • 在Windows上

    jmeter -JfilePath=%your_environment_variable% -n -t test.jmx
    
  • 在Unix及其衍生版本上:

    jmeter -JfilePath=$your_environment_variable -n -t test.jmx
    

有关JMeter属性以及设置和覆盖它们的方法,请参见Apache JMeter Properties Customization Guide

如果您通过Maven运行JMeter测试-您将需要通过propertiesUser部分声明相关属性:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.example</groupId>
    <artifactId>jmeter</artifactId>
    <version>1.0-SNAPSHOT</version>

    <build>
        <plugins>
            <plugin>
                <groupId>com.lazerycode.jmeter</groupId>
                <artifactId>jmeter-maven-plugin</artifactId>
                <version>2.9.0</version>
                <configuration>
                    <propertiesUser>
                        <filePath>${env.filePath}</filePath>
                    </propertiesUser>
                </configuration>
                <executions>
                    <!-- Run JMeter tests -->
                    <execution>
                        <id>jmeter-tests</id>
                        <goals>
                            <goal>jmeter</goal>
                        </goals>
                    </execution>
                    <!-- Fail build on errors in test -->
                    <execution>
                        <id>jmeter-check-results</id>
                        <goals>
                            <goal>results</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>


</project>