0
votes

I am looking for groovy script to add an wsdl to a project in SOAPUI dynamically at runtime using groovy scripts. i have tried the following code

import com.eviware.soapui.impl.wsdl.*

import com.eviware.soapui.impl.WsdlInterfaceFactory


project = new WsdlProject()
//wsdl = new WsdlInterfaceFactory()

project.setName("Project1");

WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project, "C:\\Manoj\\BIAScalarReads\\IDSRequestLIB\\IDS_Request_MeterData.wsdl", true)[0];

No new project is getting loaded in the SOAPUI. Can anyone help on this?

1

1 Answers

0
votes

You're creating a project, however then you don't add the project to the Workspace. To do so you must use the related method from Workspace class.

It possible to do so in a different ways. For example, create your project, save on disk and then load on the workspace in your groovy script testStep inside a testCase:

import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory

def project = new WsdlProject()
project.setName("Project1")
WsdlInterfaceFactory.importWsdl(project, 'path/to/yourWsdl', true)

// file to save the project
def projectFilePath = 'C:/temp/myProject.xml'
// save the project
project.saveAs(projectFilePath) 
// load the project from disc to workspace
testRunner.testCase.testSuite.project.workspace.importProject(projectFilePath)

Another possible and more compact way to do the same is using workspace.createProject this way you avoid to save the disc and then import, to do it this way you can use the follow script:

import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.WsdlInterfaceFactory

def workspace = testRunner.testCase.testSuite.project.workspace
def project =   workspace.createProject('Project2',new File('C:/temp/myProject.xml')) 
WsdlInterfaceFactory.importWsdl(project, 'path/to/yourWsdl', true)

Hope this helps,