Forum Discussion

jerr's avatar
jerr
Occasional Contributor
7 years ago
Solved

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.

  • 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?
  • 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

4 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    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?
    • jerr's avatar
      jerr
      Occasional Contributor

      My use case is that I wanted to put two projects in two different workspace. From project 1 I wanted to be able to run project 2. Is it possible to do that?

      Thanks for your suggestion. I will definitely do as you said if what I planned is not possible.

      • bagochips's avatar
        bagochips
        Contributor

        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