Forum Discussion

mmoser18's avatar
mmoser18
Frequent Contributor
9 years ago

Operations on Custom properties before replacement

I am doing response assertions using regular expressions. The responses contain certain fragments that echo values from the  requests arguments, i.e. if the request is e.g.:

http://some.url/some/path?argument=foobar

the regex will read something like

<some reg-exp pattern here>$[argument]<some more reg-exp pattern here>

 

But unfortunately the response contains the echoed argument not "as-is" but converted to upper case, i.e. instead of:

<some response text>foobar<some more response text>

the response reads: 

<some response text>FOOBAR<some more response text>

 

 

I.e. the echoed value is converted to upper case and thus the above regexp does not match. To get a regexp that matches I would need top be able to define a regexp like:

<some reg-exp pattern here>$[argument.toUpperCase()]<some more reg-exp pattern here>

Is something like that do-able?

 

  • Hi,

     

    Thanks for the edit to your question, but I think my answer is still just as relavent? Alhough the first option I suggested is probably overkill, how about just doing a Script Assertion as per my second suggestion?

    Or perhaps I am missing something, but say you have TestSteps like:

     

    1. Goovy TestStep with

    context["argument"]="abcdef" //set initial value of your parameter

    2. REST Request TestStep

     

    In your Contains Assertion you can use ${=argument.toUpperCase()} to look for ABCDEF?

     

    Also in your Contains Assertion, its less exact, but you could even tick 'ignore case' e.g.

     

     

     

    Is this on the right track for what you want?

     

    Cheers,

    Rupert

     

  • mmoser18's avatar
    mmoser18
    Frequent Contributor

    It seems impossible to enter text fragments that contain closing curley brackets. Everything from a curley bracket onwards is swalloed by this fine forum-SW! So I changed all curley brackets to square brackets hoping to get my point across. You may want to have a look for a more robust forum SW  ||-(

     

    • nmrao's avatar
      nmrao
      Champion Level 3
      Please check if you can edit the questions above as those not clear.

      While defining regular expressions, it may involve special characters, so you may need to escape them properly. This is just general input.
      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Hi,

         

        If I'm understanding you right, you want to preprocess some properties extracted from the response before then applying standard Assertions to them?

         

        If so, one such approach would be to use a Response Filter to change the response values before applying the Assertions - see 

         

        https://www.soapui.org/scripting---properties/custom-event-handlers.html (gives some background, but is really for the paid for version of SoapUI)

         

        See also point 6 of https://www.soapui.org/scripting-properties/tips-tricks.html

         

        It can also be done on the open source version, but requires coding effort, which may be more effort than its worth in this case.

         

        Instead, have you considered using a Script Assertion instead? That way you could just extract the values from the response e.g. something like

         

        def prop = context.expand( '${#Project#propertyA}' )
        
        assert prop.toUpperCase()=="....."
        
        

        Is this the kind of thing you were meaning?

         

        Cheers,

        Rupert