Forum Discussion

Elsevier_-_OH_S's avatar
Elsevier_-_OH_S
Contributor
11 years ago

[Res]REmoving some part of response during assertions

Hi I am trying to put check point using For Content assertion For my whole response posted below.....<ns2:d>5</ns2:d>
<ns2:me>DSc</ns2:me>
<ns2:tN>7</ns2:tN=>
<ns2:su>
<ns2:I>7</ns2:I>
<ns2:m>A</ns2:m>
<ns2:r>7</ns2:r>
</ns2:su>
<ns2:pl>p</ns2:l>
<ns2:dg>N</ns2:dg>
<ns2:ds>B</ns2:ds>
<ns2:s>ne</ns2:s>
<ns2:p>CE</ns2:p>
<ns2:y>AL</ns2:y>
<ns2:t>true</ns2:t>
<ns2:d>false</ns2:d>
<ns2:l>nobody.com</ns2:l>
<ns2:o>(12943071)</ns2:o>
<ns2:b>false</ns2:b>
<ns2:s>C99</ns2:s>
<ns2:e>en</ns2:e>

<ns2:A>
<ns2:All>34</ns2:ALL>
<ns2:st>C291210</ns2:st>
<ns2:Date>25-Mar-2014 08:01:32</ns2:Date>
<ns2:ehr>true</ns2:ehr>
</ns2:Info>
<ns2:IDs>
<ns2:id>1</ns2:id>
<ns2:id>4</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>6</ns2:id>
<ns2:id>0</ns2:id>
<ns2:id>2</ns2:id>
<ns2:id>3</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>9</ns2:id>
<ns2:id>0</ns2:id>
<ns2:id>3</ns2:id>
<ns2:id>8</ns2:id>
<ns2:id>9</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>10</ns2:id>
<ns2:id>22</ns2:id>
<ns2:id>23</ns2:id>
<ns2:id>26</ns2:id>
<ns2:id>27</ns2:id>
<ns2:id>28</ns2:id>
<ns2:id>33</ns2:id>
<ns2:id>38</ns2:id>
<ns2:id>39</ns2:id>
<ns2:id>43</ns2:id>
<ns2:id>44</ns2:id>
<ns2:id>50</ns2:id>
<ns2:id>51</ns2:id>
<ns2:id>67</ns2:id>
<ns2:id>367</ns2:id>
<ns2:id>69</ns2:id>
<ns2:id>70</ns2:id>
<ns2:id>83</ns2:id>
<ns2:id>15</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>20</ns2:id>
<ns2:id>71</ns2:id>
<ns2:id>21</ns2:id>
<ns2:id>92</ns2:id>
<ns2:id>67</ns2:id>
<ns2:id>69</ns2:id>
<ns2:id>65</ns2:id>
<ns2:id>67</ns2:id>
<ns2:id>70</ns2:id>
<ns2:id>74</ns2:id>
<ns2:id>95</ns2:id>
<ns2:id>73</ns2:id>
</ns2:IDs>
<ns2:wedReg>NONE</ns2:wedReg>
<ns2:s>53I1T2WvEy25jjPdnj5xaCgRGGYltmlCqr3q7rjHf9y</ns2:s>
</ns2:Info>
<ns2:A>

MY problem is i want to Remove below all IDs tag becaue it is very dynamic, some time these tags increase and decreases and va;ues change accordingly. I want to keep all other tags above in the response. Is there any way i can assert full response removing only this tag. I have no of test cases that needed this solution. wHEN I AM USING fOR CONTENT ASSERTION i cant use wild card or just remove this from For content assertion bcz it counts all the tags in the response and fails. Please help with any solution. In my previous post on regular expression ur tean comes up with a solution for one of my tag value , from there i removed part of a string with the below code using Moc service and RequestFilter.afterRequest....But this was only for one case as i have to change test name in the event handler code, i want to use it for multiple cases.


if ( context.getCurrentStep().getLabel() == "Test Request: search")
{
log.info "here we go"
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context )
def holder = groovyUtils.getXmlHolder(context.httpResponse.responseContent)
holder.namespaces["sam"] = 'http://www.soapui.org/sample/'
def price = holder.getNodeValue("//sam:searchResponse[1]/item[1]/price[1]")
def idx = price.indexOf("CON|")
def idx2 = price.indexOf(",",idx)
def valueToRemove = price.substring(idx+4,idx2)
log.info valueToRemove
price = price.replace(valueToRemove,"")
holder.setNodeValue("//sam:searchResponse[1]/item[1]/price[1]",price)
context.httpResponse.responseContent = holder.xml
}



<ns2:IDs>
<ns2:id>1</ns2:id>
<ns2:id>4</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>6</ns2:id>
<ns2:id>0</ns2:id>
<ns2:id>2</ns2:id>
<ns2:id>3</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>9</ns2:id>
<ns2:id>0</ns2:id>
<ns2:id>3</ns2:id>
<ns2:id>8</ns2:id>
<ns2:id>9</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>10</ns2:id>
<ns2:id>22</ns2:id>
<ns2:id>23</ns2:id>
<ns2:id>26</ns2:id>
<ns2:id>27</ns2:id>
<ns2:id>28</ns2:id>
<ns2:id>33</ns2:id>
<ns2:id>38</ns2:id>
<ns2:id>39</ns2:id>
<ns2:id>43</ns2:id>
<ns2:id>44</ns2:id>
<ns2:id>50</ns2:id>
<ns2:id>51</ns2:id>
<ns2:id>67</ns2:id>
<ns2:id>367</ns2:id>
<ns2:id>69</ns2:id>
<ns2:id>70</ns2:id>
<ns2:id>83</ns2:id>
<ns2:id>15</ns2:id>
<ns2:id>5</ns2:id>
<ns2:id>20</ns2:id>
<ns2:id>71</ns2:id>
<ns2:id>21</ns2:id>
<ns2:id>92</ns2:id>
<ns2:id>67</ns2:id>
<ns2:id>69</ns2:id>
<ns2:id>65</ns2:id>
<ns2:id>67</ns2:id>
<ns2:id>70</ns2:id>
<ns2:id>74</ns2:id>
<ns2:id>95</ns2:id>
<ns2:id>73</ns2:id>
</ns2:IDs>

7 Replies

  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Following this tip here: http://www.soapui.org/Scripting-Properties/tips-a-tricks.html#6-changing-response-before-it-gets-validated, you can use this script in a RequestFilter.afterRequest Event Handler to remove the ID's part of your response, as long as all the requests you expect it to apply to will have that same same response format.

    if( request.response == null )
    return

    // get response content
    def content = context.httpResponse.responseContent
    //log.info content

    def sub1 = content.substring(0, content.indexOf("<ns2:IDs>"))
    //log.info "sub1: " + sub1
    def sub2 = content.substring(content.indexOf("</ns2:IDs>")+10)
    //log.info "sub2: " + sub2
    content = sub1 + sub2
    //log.info content

    // write it back
    context.httpResponse.responseContent = content


    Regards,

    Giscard
    SmartBear Support
  • Thanks for the solution Giscard. I tried this solution but no luck yet....Just want to confirm do i have to use mock service with it or not.
  • It is giving an error saying expected presence of child nodes to be'false' but was true comparing <ns2:IDs>
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    Can you open a case on the following link?
    http://www.soapui.org/Support/support-overview.html

    Please attach the project (Right click on the project > Export Project), so we can investigate further. Also attach the screenshot for Request and response so we can see if the nodes are present after the script is executed.

    Also send us the script and error log, they are at the bottom tab, right click on SoapUI log and error log export to file.

    "error saying expected presence of child nodes to be'false' but was true comparing <ns2:IDs>" when do you receive this error.

    Thanks,
    Jeshtha
  • the above soapui script works at test step level and failed at test suit or test case level or Project level for event "RequestFilter.afterRequest"