Forum Discussion

dario_canto's avatar
dario_canto
New Contributor
8 years ago

Refactoring a Request so it change in all its test cases

I have been using the unlisenced version of SoapUI for a couple of weeks, up until I encountered this problem.   I built a project full of REST requests, each of them with a json body with differen...
  • groovyguy's avatar
    groovyguy
    8 years ago

    So, here's an example of what I mean. Some of the SOAP services I test as part of my job can go through what I call "schema churn." Where there is a defect with the WSDL/XSD files that cause new versions to be put out. Sometimes these new WSDL/XSD files are 99.9% the same and only change how an element is define (regex pattern, etc.)

     

    The problem is when these WSDL/XSD files change significantly enough that the actual XML of the requests has new elements or some are no longer present. This means that all of my tests (sometimes hundreds of them) need to change. This is problematic because of what you said. It's tedious and untenable to have to manually update these tests.

     

    I have written a groovy script that can, with the right setup, take a request, or the content thereof, make the necessary changes and save it back to the test step. So let's say I have an old WSDL/XSD set that has the following element:

     

    <element>
          <child1/>
          <child2/>
          <child3/>
    </element>
    

    And all of my tests are based off of that. Let's say the new WSDL/XSD file has:

    <element>
          <child1/>
          <child2/>
          <child3>
                <grandchild1/>
                <grandchild2/>
          </child3>
    </element>
    

    That means all of my tests are now out of date. So I would write a groovy script that steps through every test suite in the project, every test case in each test suite, and each test step in each test case. If the test step needs to be updated (you will need to have the appropriate groovy logic in place for this), you will do :

     

    // Psuedocode
    
    def oldRequest = testStep.getRequestContent();
    def newRequest = oldRequest.replaceAll("<child3/>", <child3>\n<grandchild1/>\n<grandchild2>");
    
    testStep.setRequestContent(newRequest);