cancel
Showing results for 
Search instead for 
Did you mean: 

Automate Environment creation for REST and SOAP services

Community Hero

Automate Environment creation for REST and SOAP services

This came up in a previous thread, and I've finally worked out how to populate environments into a project and how to set their endpoints accordingly. This is relatively simple and can be extended for adding multiple environments. We're currently using this to convert all of our various ReadyAPI / SoapUI NG Pro projects to support environments. It's working like a charm!

 

// For REST Services

import com.eviware.soapui.model.environment.*
import com.eviware.soapui.config.*

def project = context.testCase.testSuite.project;

 // Assuming binding is the first interface on the project.
 def binding = context.testCase.testSuite.project.getInterfaceAt(1).getName().toString();

 // Getting current list of environment names
def environNames = project.getEnvironmentNames().toString();

 // Names of environments to add
def name = "env1"

// Environment URLs, number should match number in previous array for environment names

project.addNewEnvironment(name);
project.setActiveEnvironment(name);

def environ = project.getActiveEnvironment();

def newService;

	// For REST service: 
 	newService = environ.addNewService(binding, com.eviware.soapui.config.ServiceConfig.Type.REST);

	def serviceConfig = newService.getConfig();

	
	def endpointConfig;
	
	endpointConfig = serviceConfig.addNewEndpoint();
	
	
	newService.buildEndpoint(endpointConfig);
	def isCopy1 = true;
	
	log.info(isCopy1);
	environ.populateService(newService, isCopy1);

	environ.release();
	

For SOAP services:

import com.eviware.soapui.model.environment.*
import com.eviware.soapui.config.*

def project = context.testCase.testSuite.project;

 // Assuming binding is the first interface on the project.
 def binding = context.testCase.testSuite.project.getInterfaceAt(1).getName().toString();

 // Getting current list of environment names
def environNames = project.getEnvironmentNames().toString();

 // Names of environments to add
def name = "env1"

// Environment URLs, number should match number in previous array for environment names

project.addNewEnvironment(name);
project.setActiveEnvironment(name);

def environ = project.getActiveEnvironment();

def newService;

	// For SOAP service:
	newService = environ.addNewService(binding, com.eviware.soapui.config.ServiceConfig.Type.SOAP);
 	// For REST service: 
 	// newService = environ.addNewService(binding, com.eviware.soapui.config.ServiceConfig.Type.REST);

	def serviceConfig = newService.getConfig();

	
	def endpointConfig;
	
	endpointConfig = serviceConfig.addNewEndpoint();
	
	endpointConfig.setStringValue(url)
	
	newService.buildEndpoint(endpointConfig);
	def isCopy1 = true;
	
	log.info(isCopy1);
	environ.populateService(newService, isCopy1);

	environ.release();
	

The two are almost identicle except for a couple of lines. Other than that, these have both worked for me without any problems. 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
3 REPLIES 3
Community Manager

Re: Automate Environment creation for REST and SOAP services

Great example, Matthew! Thanks for preparing it and sharing with the Community

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Community Hero

Re: Automate Environment creation for REST and SOAP services

Always happy to share, @TanyaGorbunova! I've seen a number of posts here looking for something similar, so I hope it helps others out. Smiley Happy 




---

Click the Accept as Solution button if my answer has helped, and remember to give kudos where appropriate too!
Super Contributor

Re: Automate Environment creation for REST and SOAP services

Thats why I refer to as a legend!

Thanks man

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2