Reputation: 21
I have a simple Jmeter test where I have a property to set the URL. The PATH in the Jmeter test is set to the following.
${__P(GET_URL,)}
This works well for all URLs that I have been working with, except for the ones where I need to pass a variable in the URL component.
For example, it works for http://server:port/getemployeelist
when I run the test with -JGET_URL=/getemployeelist
Then I created a CSV config element to populate the variable EMP_ID
.
Then if I run the test with -JGET_URL=/getemployee/${EMP_ID}
, the EMP_ID
variable is not getting substituted. Jmeter test gives me an error as follows:
java.net.URISyntaxException: Illegal character in path at index xx: https://://getemployee/${EMP_ID}
Appreciate any help/pointers.
Upvotes: 1
Views: 12381
Reputation: 21
Had asked this question a while back. Thought of posting the solution which I eventually ended up implementing. In the solution, I created a template jmx with a substitution variable for the HttpSampler.path and then replace the path at runtime. Following are the key points from the scripting done.
This turned out to be a simpler solution that worked for all kinds of API call patterns.
<stringProp name="HTTPSampler.path">#PATH#</stringProp>
This jmx has CSV config element to populate variable "EMP_ID". To create this file, just create a new test with any URL and then save it as a template and replace the URL with substitution variable #PATH#.
sh run_any_api.sh URL=http://server:port/myapp/employees/${EMP_ID}
sed "s/#PATH#/$URL" jmeter_test_template.jmx > jmeter_test_template.current_test.jmx
jmeter -t jmeter_test_template.current_test.jmx
rm jmeter_test_template.current_test.jmx
Upvotes: 0
Reputation: 168132
It will not work this way, JMeter doesn't know anything about ${EMP_ID}
at the time it is being started, you need to append this ${EMP_ID}
to HTTP Request sampler "Path" in the runtime
Start JMeter as:
jmeter -JGET_URL=/getemployee/
Use CSV Data Set Config to read the EMP_ID
from the CSV File
In the HTTP Request sampler use construction like /${__P(GET_URL,)}/${EMP_ID}
to combine JMeter Property specified via -J
command line argument and JMeter Variable originating from the CSV file.
If anything goes wrong first of all check jmeter.log file - it normally contains enough troubleshooting information. If there is nothing suspicious - use Debug Sampler and View Results Tree listener combination to inspect requests and response details, variables and properties names and values, etc.
Upvotes: 0