cancel
Showing results for 
Search instead for 
Did you mean: 

Groovy script to open Project

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Hero

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!

View solution in original post

5 REPLIES 5
Highlighted
Community Hero

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!

View solution in original post

Highlighted
Community Hero

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.
Highlighted
Community Hero

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!
Highlighted
Community Hero

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.
Highlighted
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?

New Here?
Join us and watch the welcome video:
Announcements
TechCorner Leaderboard
Want a fun and easy way to learn ReadyAPI and show off your skills? Try solving weekly TechCorner challenges and get into the Leaderboard!


Challenge Status

Get a full Raw JMS request

Participate!

Compare an expected JSON value and actual response in Events

Participate!

Fetch value/data from JSON response using Groovy Script

See replies!

Get data from Petstore and add it to Excel sheets

Participate!
Top Kudoed Authors