SoapUI如何通过Groovy Script更新WSDL定义和重新创建请求

时间:2015-02-11 05:51:58

标签: groovy soapui

我在SoapUI中有一个肥皂测试项目。我已将所有请求添加为测试套件中的测试步骤。

我需要每次开始测试时都会更新WSDL定义并重新创建请求(同时保留现有值)。

我需要帮助才能在一个groovy脚本的帮助下自动执行此过程,该脚本可以放在项目中并在执行开始之前每次运行。

3 个答案:

答案 0 :(得分:1)

现在就开始工作.. 这是完整的代码..

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//

希望这可以帮助其他人寻找类似的解决方案。

答案 1 :(得分:0)

如果您手头有更新的wsdl文件,则使用UpdateWSDLDefinition.groovy脚本更新服务界面&amp; 项目测试用例的测试请求。 。

/**
*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()

答案 2 :(得分:0)

我想通过goovy脚本更新定义。 以下脚本将更新wsdl定义。 现在我需要一个脚本来根据更新的模式重新创建我的所有请求。

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() + "'";

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

现在需要一个脚本来根据更新的模式重新创建所有请求(保留现有值)