Forum Discussion
PaulDonny
11 years agoRegular Contributor
Here is a sample script that does what you want, it's in Groovy so it would require a groovy step. I am certain that there is better ways to do this but I used regexp in order to make it more versatile for other uses.
First example, used for matching counting all child elements:
Example 2 is the same, except change the regexp line to:
Where ElementOfList is the value you want. After your done counting, do whatever you want. The logic for the count and code is in the matcher.each section so if you want to manipulate the data just do it[2] for the value of the node and it[1] for the node's name.
First example, used for matching counting all child elements:
def testRan = context.testCase.getTestStepByName("Test Request");
def xml = testRan.getPropertyValue("Response");
def regexp = ("(?m)<([^<>]+)>(.*?)</\\1>");
def matcher = xml =~ regexp;
int count = 0;
matcher.each {
count++;
}
log.info count;
Example 2 is the same, except change the regexp line to:
def regexp = ("(?m)<(ElementOfList)>(.*?)</\\1>");
Where ElementOfList is the value you want. After your done counting, do whatever you want. The logic for the count and code is in the matcher.each section so if you want to manipulate the data just do it[2] for the value of the node and it[1] for the node's name.
Related Content
- 7 months agoḥari
- 2 years agoDesktopapptesti
- 2 months agoStoplight
Recent Discussions
- 6 days agoemoya