Search code examples
groovysoapuitest-runner

SoapUI Groovy script: Create new project using command line


I am trying to create Soapui project using groovy script. When running it directly from SoapUI, the Script is working correctly and new Project with WSDL is created.

The script is created in: Project -> TestSuite -> TestCase -> Groovy script

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

String Release = "xxx.yyy";
String projectName = "Test_$Release" + ".xml";
String projectPath = "D:/work/";
String fullProjectPath = "$projectPath$projectName";
String pathToWSDL = "D:/work/AWSECommerceService.wsdl.xml";
log.info ("Release value is $Release");
log.info ("Projet path is $projectPath");
log.info ("Project name is $projectName");
log.info ("pathToWSDL $pathToWSDL");
log.info ("fullProjectPath $fullProjectPath");

def currentProject = testRunner.testCase.testSuite.project;

WsdlProject project = currentProject
                        .getWorkspace()
                        .createProject(projectName, new File(fullProjectPath));
 WsdlInterface iface = WsdlInterfaceFactory.importWsdl(project,pathToWSDL, true )[0]
context.testCase.testSuite.project.save("");

The script is working correctly when from SoapUI. But, failing when run it using testrunner.bat as given below:

testrunner.bat "D:\Ivo\Project.xml"

It is returning following error:

Error:java.lang.NullPointerException: Cannot invoke method createProject() on null object


Solution

  • Can you try change as given below:

    From:

    WsdlProject project = currentProject
                            .getWorkspace()
                            .createProject(projectName, new File(fullProjectPath));
    

    To:

    WsdlProject project = new WsdlProject();
    project.setName(projectName);
    //your statements goes here
    //finally save project
    project.saveAs(fullProjectPath);