cancel
Showing results for 
Search instead for 
Did you mean: 

Asserting a partial XML using regex

0 Kudos

Asserting a partial XML using regex

Hi All,

 

Is there any assertion in Soapui Pro, that can be used to assert the response XML partially using regex pattern.

 

For Eg : Lets assume the response XML is something like this below:

 

<root>

<a1>This is a1 test</a1>

<a2>adding a2 text</a2>

<a3>

<b1>Some random text</b1>

<c1>hello</c1>

</a3>

</root>

 

And i want to assert this xml partially using some regex. Lets say like this below:

 

Contains Assertion: 

<root>

<a1>This is a1 test</a1>

*.*

</a3>

</root>

 

-----------------------------------

 

When i actually try to do this, it's not working. Can some suggest me the actual regex pattern that can be applied on the above XML to assert its response body. (Note : I am making use of 'contains' assertion)

 

Kindly let me know, if this feature exists (if yes, plz suggest regex for above & if NO, can we add this feature in next release of soapui pro).

 

 

Thanks

Singh

9 Comments

Hi!

Since Contains has got complete support for Regex, you CAN do it.

 

I don't unfortunately have the expression itself, but with some regex skills you can do it. Smiley Happy

Frequent Visitor

That's what I am asking for. I know, 'contains' give the option of asserting the response body. But I want to assert a response body XML, starting from root node, but i want to skip verifying the middle portion, such that i can verify the XML partially.

 

The example can be found on my first post above, how i want to apply the assertion.

KINDLY SUGGEST THE REGEX PATTERN OR IF THERE'S SOME OTHER WORKAROUND.

 

 

Thanks

Singh

Community Manager
Status changed to: New Idea
 
Staff

Hi Singh,

 

I would suggest this regex:

 

<a1>This is a1 test</a1>.+</a3>

 

I tried it in Ready!API 1.3.1

It matches

 

<root>
<a1>This is a1 test</a1>
<a2>adding a2 text</a2>
<a3>
<b1>Some random text</b1>
<c1>hello</c1>
</a3>
</root>

 

but not

 

<root>
<a1>This is a1 test</a1>
<a2>adding a2 text</a2>
<a4>
<b1>Some random text</b1>
<c1>hello</c1>
</a4>
</root>

 

Hope it helps,

/Matti

Staff
Status changed to: Accepted for Discussion
 
Community Hero

Matti,

 

Just happened to see this post, and trying out regex

 

Could match both of the cases with the following, see the attachment

regex: <a1>This is a1 test</a1>\n(.+\n)*</a\d>

 

regex2.png

 

Is that what expected by the end user?

EDIT: some how, after the post attachment is not seen.

Frequent Visitor

I have tried both the regex suggested above, but none of them seems to work:

 

For eg : Case 1:

 

<a1>This is a1 test</a1>

.+

</a3>

</root>

 

Case 2:

 

<a1>This is a1 test</a1>

\n(.+\n)*</a\d>

</a3>

</root>

 

 

None of the above works. Can someone please guide.

 

Thanks

Singh

Staff

Hi Singh,

can you supply a sample of the response that doesnt work with suggestions above?

BR

/Matti

Frequent Visitor
Hi Matti, If you see my original post, I have mentioned the sample response over there. Can someone please help me to assert the XML body partially. Refer to my original post above NOTE : I don't want to verify the contents of a2 node, but just want to assert the rest of the nodes content, i.e. a1,a3, a4, etc.. Please suggest how can i do it. I have already tried the reg ex expressions suggested in one of the comments above, but none seems to work. Regards Singh
Join the September Hub-bub to show off, learn and win