SoapUI how to Update WSDL Definition and Recreate requests through Groovy Script

自闭症网瘾萝莉.ら 提交于 2019-12-05 20:22:24

Got it working now.. Here is the complete code..

import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateRequests
import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateTestRequests

project = testRunner.testCase.testSuite.project; //get the project reference
def ifaceList = project.getInterfaceList(); //get all the interfaces present in the project in a list

//start a loop for number of interfaces
for(int i = 0; i < project.getInterfaceCount() ; i++)
{

def iface = project.getInterfaceAt(i);
def url = iface.definition;
iface.updateDefinition( url, true); //updateDefinition(String url , Boolean createRequests)

//The above part updates the definition
//The part below recreates the requests based on updated wsdl definition

//syntax - 
//recreateRequests( WsdlInterface iface, boolean buildOptional, boolean createBackups, boolean keepExisting, boolean keepHeaders )

recreateRequests(iface,true,true,true,true);
recreateTestRequests(iface,true,true,true,true);
}
//End of Script//

Hope this helps others looking for similar solution.

I got way to update definition through goovy script. The below script will update the wsdl definition. Now i need a script to recreate all my request based on the updated schema.

import com.eviware.soapui.impl.wsdl.WsdlInterface

myInterface=(WsdlInterface) testRunner.testCase.testSuite.project.getInterfaceByName("interface name");

myInterface.updateDefinition("wsdl url here", false);

log.info " WSDL definition loaded from '" + myInterface.getDefinition() + "'";

==============================================================

Need a script now to recreate all request based on updated schema (with keep existing values)

If you have an updated wsdl file in hand, then you use UpdateWSDLDefinition.groovy script to update the service interface & test requests of test case of the project. .

/**
*This script automatically update the wsdl definition and its test requests in the soapui project
*Check for the variables- projectName, wsdlFiles to be updated before running the script
*/
import com.eviware.soapui.impl.wsdl.WsdlInterface
import com.eviware.soapui.impl.wsdl.WsdlProject
import com.eviware.soapui.model.iface.Interface
import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateRequests
import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateTestRequests
/**
* Created by nmrao on 12/24/14.
*/
class UpdateWsdls {

       WsdlProject wsdlProject

        public UpdateWsdls(String projectFileName) {
            this.wsdlProject = new WsdlProject(projectFileName)
        }

        def getBindingNames(String wsdlFile) {
            def definitions = new XmlParser().parse(new File(wsdlFile))
            return definitions.getByName('*:binding').@name
        }

        void updateInterfaceDefinitions(List<String> wsdlFileNames) {
            wsdlFileNames.each { fileName ->
                def interfaceNames = getBindingNames(fileName)
                interfaceNames.each {
                    updateInterfaceDefinition(it, fileName)
                }
            }       
        }

        void updateInterfaceDefinition(String interfaceName, String fileName) {       
            List<Interface> interfacesList = wsdlProject.interfaceList
            interfacesList.each { Interface anInterface ->
                if (anInterface instanceof WsdlInterface && interfaceName.equals(anInterface.name)) {
                    WsdlInterface wsdlInterface = (WsdlInterface) anInterface
                    wsdlInterface.updateDefinition(fileName, false)
                }
            }
        }

        void updateRequests () {
            List<Interface> interfacesList = wsdlProject.interfaceList
            interfacesList.each { Interface anInterface ->
                WsdlInterface wsdlInterface = (WsdlInterface) anInterface
                recreateRequests(wsdlInterface,false,false,true,false)
                recreateTestRequests(wsdlInterface,false,false,true,false)
            }
        }

        void saveWsdlProject() {
            wsdlProject.save()
            wsdlProject.release()

        }

}

String projectName = "/path/to/abc-soapui-project.xml" //absolute path of soapui project file
List<String> wsdlFiles = ["/path/to/service1.wsdl"] //or you can have multiple wsdls from different wsdl files which you want to update in one project
UpdateWsdls updateWsdl = new UpdateWsdls(projectName)
updateWsdl.updateInterfaceDefinitions(wsdlFiles)
updateWsdl.updateRequests()
updateWsdl.saveWsdlProject()
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!