Ask a Question

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

SOLVED
tester213243
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

11 REPLIES 11
nmrao
Champion Level 3

Use regular expression.


Regards,
Rao.

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> 

 

Hi tester213243

 

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

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'. 

 

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.
Akshata9
Occasional Contributor

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

HimanshuTayal
Community Hero

@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,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
nmrao
Champion Level 3

Tried the previous reply?


Regards,
Rao.
HimanshuTayal
Community Hero

@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 🙂

 


Click "Accept as Solution" if my answer has helped,
Remember to give "Kudos" 🙂 ↓↓↓↓↓



Thanks and Regards,
Himanshu Tayal
cancel
Showing results for 
Search instead for 
Did you mean: