cancel
Showing results for 
Search instead for 
Did you mean: 

Contain assertion - how can I 'blank out' a part of element text which changes with every response

SOLVED
Highlighted
New Contributor

Contain assertion - how can I 'blank out' a part of element text which changes with every response

Hello fellow soap users, 

I am building a regression test. And the easiest way is ofcourse to make one contain-assertion of the complete response. However, there are elements that change everytime I execute. 

For example: 

       <ns1:RandomNumber>234</ns1:RandomNumber>  

Is there I way I can validate if the response contains something like: 
       <ns1:RandomNumber>XXX</ns1:RandomNumber>  

With the XXX that 'blank out' that part of the validation. So it only checks the presence of the positions, and not what it actually says there?

Kind regards

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

@tester213243 

There is an example in the documentation for the same

https://www.soapui.org/docs/functional-testing/point-and-click-testing/point-and-click-with-xpath.ht...

 

In your case, use xpath assertion with

XPath expression as

matches(//*:RandomNumber, '\d{3}')

And Exprected Result as

true

 

NOTE: ignore namespace from the image below and use your name spaces by clicking on declare.

Selection_113.png



Regards,
Rao.

View solution in original post

11 REPLIES 11
Highlighted
Community Hero

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

Use regular expression.


Regards,
Rao.
Highlighted
New Contributor

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

Hi Rao, 

Thanks for the quick reply, appreciate your time. 

But how would that work in my example if i want to use the regular expressions?

For example, apparently a dot should match any character or \d should match any digit. But if i do the following it doesn't work: 

 

Response:

       <ns1:RandomNumber>234</ns1:RandomNumber> 

Contain Assertion: 

       <ns1:RandomNumber>...</ns1:RandomNumber> 

or   <ns1:RandomNumber>\d\d\d</ns1:RandomNumber> 

 

Highlighted
Contributor

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

Hi tester213243

 

Can you try <ns1:RandomNumber>[1-9][1-9][1-9]</ns1:RandomNumber> . hope it works

Highlighted
New Contributor

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

Hi @arunbharath  

No unfortunately that doesnt work either. 

There are many numbers in my response but if i just create a contain-assertion with [1-9] it fails. 

Also if i check the box 'Use token as regular expression'. 

 

Highlighted
Community Hero

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

Instead of contains, use XPath assertion and provide the node, then use regular expression. If you are expecting 3 digits, try like

\d{3}



Regards,
Rao.
Highlighted
Occasional Contributor

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

you can use regular expression  .* to check if field is not null

Highlighted
Community Leader

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

@tester213243  :

 

instead of contains assertion use Script assertion it will check the particular node value.

User jsonSlurper to get the node value and assert like below

 

assert nodeValue != ""

 

and if you know the random value then assert like

 

assert nodeValue == expectedValue

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal
Highlighted
Community Hero

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

Tried the previous reply?


Regards,
Rao.
Highlighted
Community Leader

Re: Contain assertion - how can I 'blank out' a part of element text which changes with every respon

@tester213243  : Have you got the chance to test the solutions provided. If solved then please mark as solve as it will help other help seekers Smiley Happy

 


Click "Accept as Solution" if my answer has helped, and remember to give "kudos" Smiley Happy

Thanks and Regards,
Himanshu Tayal