How to Use Command Line Parameters in JMeter

这一生的挚爱 提交于 2020-06-13 08:32:51

问题


I'm using Jmeter for testing APIs and I want to parametrize the project's path from the terminal and then I want to use this parameter in JMeter.

The parameter that I've sent via Command Line :

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

The parameter that I've used in User Defined Variables :

${__P(url)}

But when I run my automation in JMeter, my test scripts are not going to URL that's been defined. When I check the request body, I see POST https://1 as URL.

Please see the attached photos. https://mylifebox.com/shr/3df5bb35-cf43-4488-b20b-5c2d59656212&language=en


回答1:


Let's start clean:

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

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

  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:




回答2:


Put ${__P(url)} inside Server Name field in HTTP Request.

Domain name or IP address of the web server, e.g. www.example.com. [Do not include the http:// prefix.] Note: If the "Host" header is defined in a Header Manager, then this will be used as the virtual host name.

Don't use User Defined Variables



来源:https://stackoverflow.com/questions/59139762/how-to-use-command-line-parameters-in-jmeter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!