Forum Discussion

ryanshoward's avatar
ryanshoward
Occasional Contributor
9 years ago
Solved

Contains assertion using Regex failing

Hi, I'm trying to implement some assertions using regex but I cannot get it working properly   in my soap response I have an element which looks like this:   <UploadResult>BOPS201511001CDIS-7</U...
  • nmrao's avatar
    9 years ago

    Both of your regular expressions matches intended string, however, you might be experiencing failure.

    It is because:

    1. that is only matching partial string, but not entire response
    2. if you are providing value in the content, special characters needs to be escaped

    Below regex should work i.e., match anything before and after original regex(which you mentioned)

     

    ([\\s\\S]+)(BOPS\\d{9}CDIS-\\d{1,3})([\\s\\S]+)

    You may also use Property Expansion, then no need to escape.

     

    Define Test Case level custom property, say REGEX_CONTENT with value

    ([\s\S]+)(BOPS\d{9}CDIS-\d{1,3})([\s\S]+)

     

    Use ${#TestCase#REGEX_CONTENT} as content in Contains Assertion.