【问题标题】:SoapUI how to Update WSDL Definition and Recreate requests through Groovy ScriptSoapUI 如何通过 Groovy 脚本更新 WSDL 定义和重新创建请求
【发布时间】:2023-04-08 14:25:01
【问题描述】:

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

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

我需要借助一个 groovy 脚本来自动执行此过程,该脚本可以放置在项目中并在每次执行开始前运行。

【问题讨论】:

    标签: groovy soapui


    【解决方案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//
    

    希望这有助于其他寻找类似解决方案的人。

    【讨论】:

    • 如果您希望只支持更新的请求,但更新以下行。 . . iface.updateDefinition( url, false);
    【解决方案2】:

    我有办法通过 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() + "'";
    

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

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

    【讨论】:

      【解决方案3】:

      如果您手头有更新的 wsdl 文件,那么您使用UpdateWSDLDefinition.groovy 脚本来更新项目的测试用例的服务接口 & 测试请求。 .

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

      【讨论】:

      • 如果没有外部 wsdl 文件,请建议如何使用它。如果请求结构有任何变化,我想根据现有项目 wsdl 更新请求。还建议将此脚本保留为常规步骤还是在设置脚本中?
      • 您可能最初基于某些 wsdl 创建了项目。因此,我相信同一个 wsdl 文件中存在更改,因此您可以提供该文件。该脚本就是为此目的而设计的。如果是在线wsdl,则可以保存并提供位置。
      • 如果我将 wsdl 保存在文件中并在soapUI 项目中提供该位置。当 wsdl(服务或结构)发生任何更改时,我的 wsdl 将如何更新(有新的更改),因为现在我总是指的是我保存的静态 wsdl 文件。希望你能得到我的关心。 -------------------------------------------------- ----------------------------------
      • 我正在使用开发团队可以更新的 wsdl 创建我的测试项目。所以我需要一个脚本,每次执行前更新wsdl和所有请求(使用更新的wsdl),这样如果开发团队在请求结构中有任何更改,它就会反映在我的soapui请求中,我们可以跟踪变化。 -------------------------------------------------- ---------------------------------------------
      • 请注意,soapui 项目需要使用更新后的 wsdl 文件进行更新,这可能会导致开发人员对架构进行更改。该脚本提供了这项工作,包括更新来自套件的现有测试请求。有没有简短的运行脚本?
      猜你喜欢
      • 1970-01-01
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2013-08-25
      相关资源
      最近更新 更多