I need to extract uuid from the below XML response using xpath extractor in jmeter. Can anyone help me with the expression>
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope xmlns:soap="schemas.xmlsoap.org/soap/envelope/" xmlns:awsse="xml.test.com/2010/06/Session_v3" xmlns:sca="www.w3.org/2001/05/addressing"><soap:Header><sca:To>www.w3.org/2005/08/addressing/anonymous</sca:To><sca:From><sca:Address>nodeA1.test.webservices.test.com/1ASIRFCUCPA</sca:Address></sca:From><sca:Action>webservices.test.com/test_Shopping_18.1</sca:Action><sca:MessageID>urn:uuid:ba154abc-636c-33b4-3947-6b50651b3f5b</sca:MessageID><sca:RelatesTo RelationshipType="www.w3.org/2005/08/addressing/reply">urn:uuid:55c875fa-bda3-461e-aa06-56c28f11ad38</sca:RelatesTo>
Assuming that you're looking for the MessageID:
You can use XPath name() function to extract the value like urn:uuid:ba154abc-636c-33b4-3947-6b50651b3f5b. The relevant expression would be:
(//*[name() = 'sca:MessageID'])/text()
If you want just this ba154abc-636c-33b4-3947-6b50651b3f5b part - go for substring() function like:
substring((//*[name() = 'sca:MessageID'])/text(),10)
More information:
XPath Tutorial
Using the XPath Extractor in JMeter
Related
Response is {"d":"14049,171681785,347225778"} and I want to extract the value 171681785 from response
Can somebody help me how to write regular expression to extract 171681785 from the above response?
Since 14049 can change, i can advise you to use JSON Extractor indeed. After getting the value of d with $.d, you can use this code in JSR223 Post Proccesor to get the value in the middle.
String[] array = vars.get("yourVariableName").split(",");
vars.put("theValueYouWant", array[1]);
i'am using jmeter "Regular Expression Extractor",my response looks as below
[{"#class":"com.test.dto.BoardDTO",
"ReadOnly":false,
"author":"John",
"id":"89BC331D723F",
"isPublic":false
},
{"#class":"com.test.dto.BoardDTO",
"ReadOnly":false,
"author":"Alex",
"id":"FTH7JBDRF567",
"Public":false
}]
I need to extract all IDs of class:"com.test.dto.BoardDTO" in this case "89BC331D723F" and "FTH7JBDRF567"
Any proposition please !
You should use JSON Extractor instead of regular expression extractor
Add a JSON Extractor and fill in the fields as below
JSON path expression: $.[*][?(#.#class == "com.test.dto.BoardDTO")].id
Match Numbers: -1
This will return all IDs where #class value was com.test.dto.BoardDTO. You can validate it using View Results Tree & Debug Sampler combination.
Preamble
I have a JMeter script with an XPath Extractor, in this I have specified a query that gets multiple values from the XML document. This all works fine
XML
<?xml version="1.0" encoding="UTF-8"?>
<InventoryAvailabilityAdvice>
<Warehouse>WFC2</Warehouse>
<Timestamp>2019-07-31T23:00:02.177</Timestamp>
<InventoryItem>
<ItemNumber>80903</ItemNumber>
<AvailableQuantity UnitOfMeasure="EA">13</AvailableQuantity>
</InventoryItem>
<InventoryItem>
<ItemNumber>80901</ItemNumber>
<AvailableQuantity UnitOfMeasure="EA">17</AvailableQuantity>
</InventoryItem>
</InventoryAvailabilityAdvice>
Problem
When I then try to get these values in a loop using a JSR232 Sampler they don't seem to come out in the order declared in the XPath Query.
I expected theData_2 to contain the UnitOfMeasure attribute and theData_3 to contain the quantity, but as you can see they are reversed.
Question
Is this expected behavior? If so, when an element has multiple attributes how do I know which order those will be made available as?
Thanks
The order of XPath nodesets produced by union operator is not guaranteed, you can see putValuesForXPathInList() function for implementation details
Actually if you've decided to go for Groovy - you don't even need the XPath Extractor, you can use XmlSlurper class for parsing the XML response.
Example code:
def response = new XmlSlurper().parseText(prev.getResponseDataAsString())
response.InventoryItem.eachWithIndex { item, index ->
log.info('Item: ' + index)
log.info('ItemNumber: ' + item.ItemNumber)
log.info('AvailableQuantiry: ' + item.AvailableQuantity)
log.info('UnitOfMeasure:' + item.AvailableQuantity.#UnitOfMeasure)
}
Demo:
References:
Groovy: Processing XML
Apache Groovy - Why and How You Should Use It
Is it possible to check two or more variables when mocking a response using SoapUi?
Here's a sample of the request:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:crm="http://www.example.com/project/wsdl/crm/">
<soap:Body>
<crm:SearchCustomer>
<FirstName>Francis</FirstName>
<LastName>Zabala</LastName>
</crm:SearchCustomer>
</soap:Body>
</soap:Envelope>
Here's the Extract Xpath
declare namespace crm='http://www.example.com/project/wsdl/crm/';
declare namespace soap='http://www.w3.org/2003/05/soap-envelope';
//crm:SearchCustomer[1]/FirstName
Expected value:
Francis
What about if I also want to check the last name?
You can try using the follow XPath expression which check for the text content of the <FirstName> and <LastName> and use boolean() XPath function to check if the expression it's accomplished or not. Also SOAPUI supports the use of * as a wildcard for namespaces so your expression could be:
boolean(//*:FirstName[text() = 'Francis'] and //*:LastName[text() = 'Zabala'])
And as expected value:
true
Having the following request:
From this I extract using the Regular Expression Extractor the following string:
%5B1172%2C63%2C61%2C66%2C69%2C68%5D
I decode this using the urldecode function: ${__urldecode(${Groups_g2})}
Decoded: [1172,63,61,66,69,68]
On the following request I want to extract the values using the BeanShell PreProcessor to obtain a list of parameters like this one:
I know that I have to use sampler.addArgument but i can't figure how to extract data from the list and add the values as parameters.
Try the following:
Put ${__urldecode(${Groups_g2})} into Beanshell PreProcessor's Parameters input field
Enter the following code into Script area
String params = Parameters.substring(1, Parameters.length() - 1); // remove square brackets
int counter = 1;
for (String param : params.split(",")) {
sampler.addArgument("parameter" + counter, param);
counter++;
}
I have no idea what parameter names need to look like, hopefully above information will be helpful.
HTTP Request with no parameters:
Beanshell PreProcessor
Parameters in View Results Tree Listener
For more information on Beanshell scripting in Apache JMeter check out How to use BeanShell: JMeter's favorite built-in component guide.