Forum Discussion

TommyTester's avatar
TommyTester
Occasional Contributor
4 years ago
Solved

Groovy script to open Project

Hi,

 

I'm writing a Groovy script step to run a test case that is within another project (Project 1 in the code snippet below). This code works if Project 1 is already open, however it fails on the second line if Project 1 is not open, for example if being run via TestRunner.

def project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName("Project 1")
def testSuite = project.getTestSuiteByName("Test Suite Name") 
def testCase = testSuite.getTestCaseByName("Test Case Name") 
def runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false)

 

Is there a way to load Project 1 if it isn't already open?

  • Here's a quick snippet you may be able to use.

     

    def workspace = context.testCase.testSuite.project.workspace;
    
    def project = workspace.getProjectByName("PROJECTNAME");
    
    if (project.isOpen() == false)
    {
         workspace.openProject(project);
    }

5 Replies

  • groovyguy's avatar
    groovyguy
    Champion Level 1

    Here's a quick snippet you may be able to use.

     

    def workspace = context.testCase.testSuite.project.workspace;
    
    def project = workspace.getProjectByName("PROJECTNAME");
    
    if (project.isOpen() == false)
    {
         workspace.openProject(project);
    }
  • nmrao's avatar
    nmrao
    Champion Level 3
    Thumb rule is that each and every test case should be independent.

    You are trying to have dependency between projects which isn't right.
    Not sure why so.
    You may need to review your tests and redesign.
    • groovyguy's avatar
      groovyguy
      Champion Level 1

      While I understand the intent of that rule of thumb, nmrao, I am curious if that's one you try to live by or if that's a standard that's been laid out somewhere? The only reason I ask is where I work, that was actually something I was not able to do all the time. Some projects had to be developed separately to match requirements, and while it made my life harder I had to work around said requirements of my job.

      • nmrao's avatar
        nmrao
        Champion Level 3
        Good that you helped the author with what he needed.
        That's one of the attribute of good automation. You should be able to find references online.

        And by the way, if someone wants to run the automated tests using testrunner, "workspace" references are not going work. Hope you aware of it.