Forum Discussion

turman's avatar
turman
Occasional Contributor
12 years ago

Issue with "contains assertions" and regular expression ?

Hi all,

I'm trying to use "contains assertions" in my test cases but I can't manage to use regular expression tokens.

I'm not very familiar with regexp but it very looks like a bug.

I have the following string in my reply : <Seatwishoptionmaxpaxnbr>02</Seatwishoptionmaxpaxnbr>

If I set "<Seatwishoptionmaxpaxnbr>02</Seatwishoptionmaxpaxnbr>" as content, and let the "Use token as regular expression" unchecked the assertion is valid.

But if I check the option, with the same content, the assertion fails !

I don't understand why it fails since the content doesn't contain any regexp token...

And if I try with a simpler content such as "Seatwishoptionmaxpaxnbr", it's the same result : the assertion is valid only if the "Use token as regular expression" is unchecked.

I've tried with SoapUI 4.5.1 and 4.6.0.

Thanks a lot for your help,

Vincent.
  • turman's avatar
    turman
    Occasional Contributor
    Hi,

    Nobody can confirm it's really a bug ?

    For me it is but maybe I'm missing a basic thing...

    It's very easy to reproduce :
    1) create a new contains assertions in a test step
    2) in the content field, set a string which really exists in your WS response => assertion is valid
    3) check the Use token as Regular Expression => assertion fails !!

    Thanks for your help, Vincent.
  • turman's avatar
    turman
    Occasional Contributor
    Up...

    I'm not sure if I have to create a bug report but if I have to I don't see any bug tracking system on soapui.org.

    Thanks for your help, Vincent.
  • redfish4ktc2's avatar
    redfish4ktc2
    Super Contributor
    Hi, there is no public bug tracker for soapui >:(
    cross your finger, maybe the SmartBear team will see your message or buy a pro license to get support
  • turman's avatar
    turman
    Occasional Contributor
    Hi,

    I have solved my problem, in fact I was confusing because I was thinking that the regexp token defined in the "Contains" assertion dialog was something to find in the content of the service's response. But that's not the case, that regexp token is something that must match with the content.

    In fact the "problem" is that SoapUI uses String.matches() for regexp which is just a convenience method :

    stackoverflow wrote:
    str.matches(regex) behaves like Pattern.matches(regex, str) which attempts to match the entire input sequence against the pattern and returns true if, and only if, the entire input sequence matches this matcher's pattern

    Whereas matcher.find() attempts to find the next subsequence of the input sequence that matches the pattern and returns true if, and only if, a subsequence of the input sequence matches this matcher's pattern


    I find it by looking into the SoapUI code but I really should have read the documentation before because in that example it was almost suggested

    But IMHO using the regex token as something to find (instead of something to match with) is much more natural, specially in the "Contains" assertion context. I'll try a pull request for that in github