Forum Discussion
MikeLoundes
12 years agoContributor
Hi folks
ok with a lot of support and patience from the support team (thanks, very much appreciated)
this did cause some head scratching as things would work when running from within the GUI but when running from command line I was getting errors, this is now sorted and running happily
the issue was that the reference project was unknown in the instance of the current project, to resolve it a workspace is initiated and the reference project imported in
the following code initiates the workspace and imports in the reference project, following on from that (within the same script) is the action to run the test case within the reference project file
ok with a lot of support and patience from the support team (thanks, very much appreciated)
this did cause some head scratching as things would work when running from within the GUI but when running from command line I was getting errors, this is now sorted and running happily
the issue was that the reference project was unknown in the instance of the current project, to resolve it a workspace is initiated and the reference project imported in
the following code initiates the workspace and imports in the reference project, following on from that (within the same script) is the action to run the test case within the reference project file
import com.eviware.soapui.impl.WorkspaceImpl;
import com.eviware.soapui.model.project.ProjectFactoryRegistry;
import com.eviware.soapui.impl.wsdl.WsdlProjectFactory;
import com.eviware.soapui.support.types.StringToStringMap;
def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
print '### Script Workspace Setup ###'
println()
//set path to reference project file
def targetDir = new File(groovyUtils.projectPath).parent //<--mod path to point to relevant directory, my ref project lives in the parent directory of the current project
def targetProjectFile = targetDir+'\\'+'someReferenceProjectFilename.xml'
def targetWorkspace = targetDir+'\\'+'default-soapui-workspace.xml' //point to whatever workspace file you are using
def targetProjectWorkspaceName = 'some project name'
//check to see if project already in workspace and import if not
def workspace = testRunner.testCase.testSuite.project.workspace
if(workspace==null)
{
workspace = new WorkspaceImpl(targetWorkspace, new StringToStringMap());
}
def isProjectInWorkspace = workspace.getProjectByName(targetProjectWorkspaceName)
if (isProjectInWorkspace == null){
def refProject = workspace.importProject(targetProjectFile.toString())
}
//check to see if project is open and open if not
def testProject = (workspace==null) ?
ProjectFactoryRegistry.getProjectFactory(WsdlProjectFactory.WSDL_TYPE).createNew(targetDir+".xml") :
workspace.getProjectByName(targetProjectWorkspaceName)
if(!testProject.open && workspace!=null) {workspace.openProject(testProject)}
print '### End Workspace Setup Script ###'
println()
// ...... do some bits then get to invocation of ref test case
//Project and Test Suite References
def TargetTestSuiteName = "some test suite name";
def TargetTestCaseName = "some test case name";
//get test case from other project or from the same one
project = workspace.getProjectByName(targetProjectWorkspaceName);
testSuite = project.getTestSuiteByName(TargetTestSuiteName);
testCase = testSuite.getTestCaseByName(TargetTestCaseName);
//set properties
testCase.setPropertyValue('somePropertyName, propertyValue);
// run test case
runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);
Related Content
- 6 years ago
- 10 years ago
Recent Discussions
- 15 years ago