Running Jmeter tests with BeanShellPostProcessor

1,345 views
Skip to first unread message

nikhilp...@gmail.com

unread,
May 8, 2018, 3:40:23 PM5/8/18
to codename-taurus
Hi,

I am trying to use Taurus to run jmeter test. But my tests uses BeanShellPostProcessor to parse repsonse from previous call and send it as an input to next call. BeanShellPostProcessor uses import statements which requires few jar files to be in lib/ext folder of jmeter. How can i do this using Taurus? Maven has an option of moving jars to lib/ext folder of jmeter in pom.xml
I tried a work around of using same pom.xml and downloading jars and moving it into jib/ext folder of jmeter.
And in my Taurus executor file i am using Jmeter file path where maven downloaded jmeter. But that did not help.

This is the error in jmeter.log file
2018-05-08 06:35:04,225 ERROR o.a.j.u.BeanShellInterpreter: Error invoking bsh method: eval     Sourced file: inline evaluation of: ``import com.eclipsesource.json.JsonObject; import com.eclipsesource.json.JsonArra . . . '' : Typed variable declaration : Class: JsonArray not found in namespace


My Taurus yml file 
execution:
- executor: jmeter
 
scenario: checkout

scenarios:
  checkout:
    script: src/test/jmeter/test.jmx
   
properties:
          user.classpath: ~/loadtest/target/jmeter-plugins-extras-libs-1.1.3.jar
         
user.classpath: ~/loadtest/target/minimal-json-0.9.5.jar
         
user.classpath: ~/loadtest/target/jmeter-plugins-manager-0.19.jar

reporting:
- module: passfail
 
criteria:
  - "fail>1% for 10s, stop as failed"

modules:
  jmeter:
    path: ~/loadtest/target/jmeter/
   
#download-link: https://archive.apache.org/dist/jmeter/binaries/apache-jmeter-3.0.zip
    #version: 3.0  # minimal supported version of JMeter is 2.9
    force-ctg: true   # true by default
    detect-plugins: true
   
plugins:
    - jpgc-json=2.2
   
- jmeter-ftp
   
- jpgc-casutg
Enter code here...



Andrey Pokhilko

unread,
May 9, 2018, 6:32:30 AM5/9/18
to codenam...@googlegroups.com

Hi,

You should use path separator to specify user.classpath property. In you config example you just specified "user.classpath" three times, which means that latest value overrides earliest. Something like

user.classpath: "~/.../jar1.jar:~/.../jar2.jar"

has to be used instead.


--

Andrey Pokhilko
Open Source Initiatives Leader
CA
          BlazeMeter

08.05.2018 22:40, nikhilp...@gmail.com пишет:
CAUTION: This email originated from outside of CA. Do not click links or open attachments unless you recognize the sender and know the content is safe.

--
You received this message because you are subscribed to the Google Groups "codename-taurus" group.
To unsubscribe from this group and stop receiving emails from it, send an email to codename-taur...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/codename-taurus/4dd75f5e-64d5-453a-bec1-4957095dbdaf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

nikhilp...@gmail.com

unread,
May 10, 2018, 2:59:23 AM5/10/18
to codename-taurus
I corrected the classpath but it still dod not help.
It is possible to download and transfer the jars from the yml file itself i.e. if i download jmeter from the path specified in download-link and then also specify path to download the jars and then move to lib/ext folder of downloaded jmeter?

Andrey Pokhilko

unread,
May 10, 2018, 3:27:07 AM5/10/18
to codenam...@googlegroups.com

When you are specifying "jmeter.path" option, it should use that JMeter instance. So you can put all required libraries into "lib" directory there.

If you want to perform some automatic actions, look at the "shellexec" service module. You can use system commands to copy files prior to test run.

--

Andrey Pokhilko
Open Source Initiatives Leader
CA
          BlazeMeter

10.05.2018 09:59, nikhilp...@gmail.com пишет:

sun...@alpha-sense.com

unread,
May 25, 2018, 7:25:47 AM5/25/18
to codename-taurus
Hi
I was trying the scenario where I am extracting one of the fields from the response then use it in another Api. I am using beanshell postprocessor. My beanshell script is working fine but I am not able to use the extracted field in the another Api. Can you pls help me in this.

My yaml code:
---
execution:
  - concurrency: 1
    ramp-up: 1s
    hold-for: 1s
    scenario: gettoken
  - concurrency: 1
    ramp-up: 1s
    hold-for: 1s
    scenario: preconnect
scenarios:
  gettoken:
     requests:
        - url: 'https://<endpoint>'
          method: POST
          headers:
            Content-Type: application/x-www-form-urlencoded
            Authorization: Basic ZXZlcm5vdGU6WW1NMVlqYzVOamN0T1dNMFppMDBPRGt5TFRsaU1qTXRObUkyT0RJeU9UVmhaRFps
          body:
            grant_type: password
            password: <password>
            username: <username>
          extract-regexp:
            AS_token:
              default: NA
              match-no: 0
              subject: response
              regexp: '"access_token":"(.*?)"'
              template: $1$
          jsr223:
            - execute: after
              language: beanshell
              parameters: null
              script-file: token.bsh
  preconnect:
     requests:
        - url: '<endpoint>'
          method: GET
          headers:
            Authorization: Bearer ${__P(AS_token_j)}
            clientid: webapp
modules:
  local:
    sequential: true

My Beansheel Postprocessor code: 
import org.apache.jmeter.util.JMeterUtils;
JMeterUtils.setProperty("AS_token_j", vars.get("AS_token"));

The same setup is working fine in jmeter.

Thanks
Shashank

Andrey Pokhilko

unread,
May 27, 2018, 4:42:37 AM5/27/18
to codenam...@googlegroups.com

Hi,

In Taurus, each scenario gets into separate JMeter script. Thus, you can't transmit properties between 2 separate JMeter processes.

You need to make token getting a part of the same scenario item.

--

Andrey Pokhilko
Open Source Initiatives Leader
CA
          BlazeMeter

25.05.2018 14:25, sun...@alpha-sense.com пишет:
My yaml code:

          

My Beansheel Postprocessor code: 
Reply all
Reply to author
Forward
0 new messages