myflowOf_99
myflowOf_99

Reputation: 69

Parametrization variables $URL using JMeter

I testing backend project in JMeter i would like can testing both localhost and url development address. i would like switch URL address in JMeter between localhost and url development address and can change $url variable between http://{$url} and ws://{$url}.

So I would like set variable $URL and can a change between websocket and http connection, such as I can have a choice if I would like send POST to a web socket or to a http connection. and i would like also can a change between localhost and development URL.

What I can the best set this in JMeter ? ;) please describe me step by step.

Upvotes: 2

Views: 9253

Answers (2)

Brent Bradburn
Brent Bradburn

Reputation: 54869

It's a little inconvenient that JMeter doesn't take an origin argument directly, but instead requires you to provide each component as a separate argument.

If you have Bash and Python at your disposal, the following one-liner will automate this process:

function jmorigin { python3<<<"from urllib.parse import *; a=urlsplit(\"$1\"); print('-Jserver='+a.hostname+' -Jprotocol='+a.scheme+' -Jport='+str(a.port))" ; }

Using this, you can simplify the parameterization of JMeter:

ORIGIN=https://example.com:443
jmeter $(jmorigin $ORIGIN)

which expands to...

jmeter -Jserver=example.com -Jprotocol=https -Jport=443

Upvotes: 0

Dmitri T
Dmitri T

Reputation: 168072

I believe you need to split your parameterization implementation in 2 parts:

  1. Protocol (http or ws). As these 2 protocols are handled by different samplers you need to have a possibility to switch between implementations basing on some variable, the easiest way to do it is going for Switch Controller, define your Test Plan as follows:

So if the ${protocol} variable value is http - you will have HTTP Request samplers executed and vice versa, check out Selection Statements in JMeter Made Easy article for detailed explanation if needed.

  1. URL variable - hopefully you know how to parameterize it, once you define its value somehow just put it into Path field of the relevant sampler

    JMeter parameterize HTTP REquest

With regards to parameterization itself, depending on where you want to have variable values there could be different approaches. Personally I stick to command-line arguments as this is the most CI-friendly way of providing external parameters.

  1. Add User Defined Variables to your Test Plan and configure it like

    enter image description here

  2. Provide the values using -J command-line argument like:

    jmeter -Jprotocol=http -JURL=example.com -n -t test.jmx -l result.jtl
    

Upvotes: 2

Related Questions