Ask a Question

Groovy script to open Project

SOLVED
TommyTester
Occasional Contributor

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?

5 REPLIES 5
groovyguy
Champion Level 0

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);
}



---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
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.


Regards,
Rao.
groovyguy
Champion Level 0

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.




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
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.


Regards,
Rao.
TommyTester
Occasional Contributor

We use a series of "helper" steps to assist with data setup etc. We don't want to maintain these across multiple projects, and would rather keep them in one centralized place that can be called from multiple projects.

 

Is there a solution so that workspace doesn't have to be used?

cancel
Showing results for 
Search instead for 
Did you mean: