Forum Discussion

jerr's avatar
jerr
Occasional Contributor
8 years ago

How can i run a project in other workspace using groovy script?

I have project1 in workspace1 and project2 in workspace2. From project2 i want to run a test suite in project1 using groovy script.   Your help is appreciated.
  • nmrao's avatar
    8 years ago
    What is your use case? why do you want do so while it is easy to run the project either from workspace or from command line utility testrunner?
  • bagochips's avatar
    bagochips
    8 years ago

    I'm not totally sure if this is what you are needing but I use this to run another project after the first project has completed. I add this code as the teardown script of the project suite.

     

    import com.eviware.soapui.impl.wsdl.WsdlProject
    def project = null
    projectPath=context.expand('${projectDir}')
    def workspace = testSuite.project.getWorkspace();
    try{
    if(workspace != null){
    project = workspace.getProjectByName("Project2")
    project = new WsdlProject(projectPath+"/Project2-soapui-project.xml");
    }
    //if running in Jenkins/Hudson
    else{
    project = new WsdlProject(projectPath+"/Project2-soapui-project.xml");
    }
    }
    catch(Exception e)
    {
    log.error("Service Exception desc : " + e.getMessage());
    }

    try{
    if(project.open && project.name == "Project2" ) {
    def properties = new com.eviware.soapui.support.types.StringToObjectMap ()
    def testCase = project.getTestSuiteByName("Project2_TestSuite").getTestCaseByName("Project2Case");
    if(testCase == null)
    {
    throw new RuntimeException("Could not locate testcase 'Project2Case'! ");
    }
    else{

    testCase.setPropertyValue("projectPath_1", projectPath )
    def runner = testCase.run(properties, false);
    }
    }
    else{
    throw new RuntimeException("Could not find project 'Project2' !")
    }
    }
    catch(Exception e)
    {
    log.error("Service Exception desc : " + e.getMessage());

    }

    project = null