Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.9k views
in Technique[技术] by (71.8m points)

Are there any advanced options of setting values of properties in jmeter properties file

I got test.properties file for my jmeter test. It contains some enviro property=value pairs and those work nicely.

But I would like to add something like this:

a1 = value
b1 = value

a2 = a1+b1
b2 = value

a3 = a2+b2
b3 = value

When I use "hardcoded" value, like 10 for a2 and 20 for a3, the properties are loaded and used correctly. But a1+b1 does not work as required. Is there any way how to assigned sum of two properties as a value of another property?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.properties file is just textual name-value pairs, it doesn't assume any evaluation logic.

  • If you need to sum 2 properties you need to go for __longSum() function like:

     ${__longSum(${__P(a1,)},${__P(b1,)},)}
    
  • If you need to store the result into another JMeter property - use __setProperty() function

     ${__setProperty(a2,${__longSum(${__P(a1,)},${__P(b1,)},)},)}
    

Demo:

enter image description here

More information on JMeter Functions concept: Apache JMeter Functions - An Introduction

Also as per Configuring JMeter user manual chapter you shouldn't be using jmeter.properties file itself for extra configuration, it should go either to user.properties or external .properties file


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...