如何在JMeter中使用命令行参数

5

我正在使用Jmeter测试API,并希望从终端参数化项目路径,然后在JMeter中使用此参数。

我通过命令行发送的参数:

./jmeter -n -t your_script.jmx -Jurl=abcdef.com

我在用户定义变量中使用的参数:

${__P(url)}

但是当我在JMeter中运行我的自动化时,我的测试脚本不会转到已定义的URL。当我检查请求正文时,我看到URL为POST https://1。

请参见附加的照片。 https://mylifebox.com/shr/3df5bb35-cf43-4488-b20b-5c2d59656212&language=en

2个回答

10

让我们从头开始:

  1. In the User Defined Variables configure the variable with the name of url and the value of ${__P(url,)}

    enter image description here

  2. In the HTTP Request sampler (or even better HTTP Request Defaults) put ${url} into "Server Name or IP" field:

    enter image description here

  3. Run your test in command-line non-GUI mode like:

    jmeter -n -t your_script.jmx -Jurl=abcdef.com -f -l result.jtl
    

    mind this -f argument which tells JMeter to overwrite the existing results file (it might be the case you're looking into "old" results where the url property value was starting with 1)

  4. That's it, you should see the HTTP Request sampler making a call to abcdef.com in the .jtl results file. And if you change this url parameter - you will see the impact in the .jtl results file:

    enter image description here


如何设置 result.jtl? - Buse Kaya

1
${__P(url)}放入HTTP请求中服务器名称字段中。

Web服务器的域名或IP地址,例如www.example.com。[不要包括http://前缀。]注意:如果在标题管理器中定义了“主机”标头,则将使用此作为虚拟主机名。

不要使用用户定义变量

我按照你说的做了,但是没有任何改变 :( 请求体 --> POST https://1: - Buse Kaya
@BuseKaya 从用户定义的变量中删除url变量。 - user7294900

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接