'Split address into house#, streetname, zip5, zip4 in JMETER
I have address example: 123 Main street, City 12345-8761 how can I split the above address into House# 123, Streetname: Main street, zip5-12345, zip4-8761 and I want to store these values in a variable and call those into XML request before I submit to service endpoint
Solution 1:[1]
It looks like the only way of achieving your goal is using JSR223 Test Elements and Groovy language
Example code:
def address = '123 Main street, City 12345-8761'
def numberAndStreet = address.split(',')[0].trim()
def cityAndZip = address.split(',')[1]
def houseNumber = (numberAndStreet =~ /(\d+)/)[0][1]
def street = numberAndStreet.replace(houseNumber, '').trim()
def zip = (cityAndZip =~ /(\d+-\d+)/)[0][1]
def city = cityAndZip.replace(zip, '')
vars.put('houseNumber', houseNumber)
vars.put('street', street)
vars.put('zip', zip)
vars.put('city', city)
Demo:
You will be able to refer the extracted values referencing the following JMeter Variables
${houseNumber}
${street}
${zip}
${city}
where required
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Dmitri T |