3

I Need to get to variable field from http request which is called Name. If anyone could give my examples how can I get other fields such as : Path, Server name or IP using beanshell?

Thank you in advance

Kac
  • 184
  • 3
  • 15

3 Answers3

5
  1. Add Beanshell PreProcessor as a child of the request
  2. Use following code lines to get the required values:

    String name = sampler.getName(); // get parent sampler name
    String path = sampler.getUrl().getPath(); // get path
    String url = sampler.getUrl().getHost();  // get IP or hostname
    

    you can also store values into JMeter Variables if required like

    vars.put("name", name);
    

See How to Use BeanShell: JMeter's Favorite Built-in Component guide for comprehensive information on using Beanshell scripting in your JMeter test.

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
2

Below code can give you the HTTP Request Name field value

ctx.getCurrentSampler().getName()

vins
  • 15,030
  • 3
  • 36
  • 47
  • keep getting lines like `String name = sampler.xxxx` from google, but none of the posts mentioned about what is `sampler`. – CHAN Jul 22 '16 at 08:19
1

I think you can do it without beanshell. Just use inside your sampler ${__samplerName()}

https://jmeter.apache.org/usermanual/functions.html#__samplerName