0

enter image description here ID[![][2]]2I am trying to write script in Beanshell preprocessor to manipulate an input text file containing a list of locations. I want to pass Location 1 as input for the 1st user's destinations, Location 2 as second user's destination and so on... I also want to send a combination of locations for some users. Please help me with this.

Thanks in advance.

1 Answer 1

1

If you need to parametrize your test so different users would use different locations from the text file - you don't even need Beanshell. Take a look at __StringFromFile() function - it reads next line from the specified file each time it's being called.

If you still want to use Beanshell - just consider it Java as it's almost Java compliant. To be completely sure that your test will work - write it J2SE 1.4-way.

Be aware that if your script logic is complex and it does something "heavy" and/or if you plan to produce immense load - it's better to consider JSR223 PreProcessor and Groovy scripting language as:

  • Groovy is even more Java-compliant than Beanshell
  • Groovy engine performance is much higher

See Beanshell vs JSR223 vs Java JMeter Scripting: The Performance-Off You've Been Waiting For! guide for different scripting engines benchmarks, instructions on installation of groovy engine and scripting best practices.

Sign up to request clarification or add additional context in comments.

5 Comments

Hi Dmitri T, Please refer my test plan design as above. I have written a script to capture the inputs from a CSV file, manipulate that and prepare input for the request. Please suggest me how to proceed with this? Also what variable to pass as the parameter value in the request.
After you perform data manipulation you can either set up a JMeter Variable as vars.put("varName", varValue); and refer it in the next sampler as ${varName} or directly using sampler shorthand which in case of HTTP Request Sampler will be HTTPSamplerProxy. See JavaDoc for the required component for details and How to Use BeanShell: JMeter's Favorite Built-in Component guide for example use cases
Hi Dmitri T, here my variable is RANDOM_NUMBER and I am passing that in my request. But in the request no random number is passing instead the variable itself is passed as is. Please suggest what changes I need to do in my Beanshell script?
Pass it as ${RANDOM_NUMBER}. Use Debug Sampler to verify its value
Hi Dmitri T, Ya, Tried this already.Not helping me. in the request tab of View Results Tree the value is passed as is : ${RANDOM_NUMBER} . Not the calculated value.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.