0

I have a question about environment properties. I used JMeter for testing Vertica + Redis + HTTP requests. for each day I get new ENV. meaning new clean DB.

the problem is that I get new host and port in env file that located for example under c://envproperties.json

Is there any way to read this json before the test plan start to run and pass the env properties to the UDV in Jmeter and than it will be fully automated process? since today it needs to be manually every day.

[enter image description here][Env properties file]

[enter image description here][User Defined Veriables in Jmeter]

Thomas Fritsch
  • 9,639
  • 33
  • 37
  • 49
Bastian
  • 1,089
  • 7
  • 25
  • 74

2 Answers2

0

You can use HTTP sampler with file protocol to get the Json file and use post processor JSon extractor to extract the values please refer to the screenshots for more information Testplan

You will get the response like this And then you can useJSon Extractorto extract the values.

You can follow this blogs for more information on JMeter

Rohit
  • 601
  • 4
  • 12
  • Hey @Rohit the problem is that I have 200 tests that use the same property, According to your solution I will need to do this process 200 times for each thread group. Is their a way to do it only once and make all the thread groups to know it?. for example that this thread group will be performed before all other tests? I want to add that all tests run simultaneously. – Bastian May 01 '18 at 14:25
  • You can share / pass one variable from one thread group to another thread group using setProperty method please refer to the mannual here http://jmeter.apache.org/usermanual/best-practices.html#bsh_variables and refer to the question https://stackoverflow.com/questions/707832/how-do-i-pass-a-variable-from-one-thread-group-to-another-in-jmeter?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Rohit May 02 '18 at 19:01
  • Hey Rohit the problem is that I want all the thread groups will run in the same time. So I do not think it can be done to pass between threads since they are run together. – Bastian May 06 '18 at 14:36
0

You can use any post processor of your choice Beanshell, JSR223 etc to extract the values out in CSV from the json via 1st threadgroup in the form of key-value pair or in two columns i.e variable_name, variable_value.

Then, 2nd Thread group may have rest of your plan along with the "jp@gc - Variables From CSV File" to get the required values, which can also be stored in system properties as shown below.

-1st Thread Group -- It is extracting value from json and putting it in csv.

  1. HTTP Request -- Getting the json from the c drive as shown
  2. Regular expression extractor - To fetch the desired variables
  3. JSR223 Post Processor - To write the variables in CSV in the form of key-value pair.

-2nd Thread Group -- It refers the csv using "jp@gc - Variables From CSV File" which provides the variables for all the below requests.

Json Test Plan in Action

Select the checkbox in test plan to Run Thread groups consecutively. I hope this help.

Community
  • 1
  • 1
sunny_teo
  • 1,961
  • 1
  • 7
  • 11
  • I still do not understand, is this process occurred before all the thread groups starts? the config file in my case is json, in the example how can I set the place where to get the variables in c drive? I need the process to get all the variables will take place before all the thread groups starts. can you please provide step by step soloution? Is their a way to set system properties via JSR223 preprocessor? will I use first preprocessor ? – Bastian May 02 '18 at 14:19
  • Updated my answer...please check if it helps you with your scenario....In my plan, i am fetching env. variables from csv and not from UDV. – sunny_teo May 02 '18 at 18:44
  • Sorry but still not understand, you mentioned first thread to do this or that, I have 100000 tests that each one of them is a thread group, I want that before anything happened Jmeter will get the ENV properties and then to process all the tests together. not one by one. Is their anyway to tell jmeter to run the first thread and than all the other together? All I want to do is that Jmeter will know where is the DB port and IP, – Bastian May 06 '18 at 13:17
  • @Bastian..First thread group will put all the required config. values in the csv...then 2nd threadgroup will take all the req. values from the csv generated by first threadgroup. Your second threadgroup will have all your 100000 thread configured. – sunny_teo May 06 '18 at 17:37