【发布时间】:2023-04-08 14:25:01
【问题描述】:
我在 SoapUI 中有一个肥皂测试项目。我已将所有请求作为测试步骤添加到测试套件中。
我需要在每次开始测试时更新 WSDL 定义并重新创建请求(同时保留现有值)。
我需要借助一个 groovy 脚本来自动执行此过程,该脚本可以放置在项目中并在每次执行开始前运行。
【问题讨论】:
我在 SoapUI 中有一个肥皂测试项目。我已将所有请求作为测试步骤添加到测试套件中。
我需要在每次开始测试时更新 WSDL 定义并重新创建请求(同时保留现有值)。
我需要借助一个 groovy 脚本来自动执行此过程,该脚本可以放置在项目中并在每次执行开始前运行。
【问题讨论】:
现在可以使用了.. 这是完整的代码..
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);
我有办法通过 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() + "'";
================================================ ===============
现在需要一个脚本来根据更新的架构重新创建所有请求(保留现有值)
【讨论】:
如果您手头有更新的 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()
【讨论】: