Reputation: 129
I have a soap test Project in SoapUI. I have added all the requests as test steps in a test suite.
I need that the WSDL definition gets updated and requests get recreated (while keeping existing values) every-time i start the test.
I need help to do this process automatically with help of a groovy script that can be placed inside the project and runs every-time before execution starts.
Upvotes: 3
Views: 7487
Reputation: 21349
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()
Upvotes: 0
Reputation: 129
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.
Upvotes: 1
Reputation: 129
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)
Upvotes: 0