cancel
Showing results for 
Search instead for 
Did you mean: 

Update definition with active environment

SOLVED
Occasional Contributor

Update definition with active environment

I am trying to update interface definition of my soap services with this script  : 

 

import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateRequests
import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateTestRequests
import com.eviware.soapui.model.ModelItem
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.model.iface.Request
import com.eviware.soapui.impl.wsdl.WsdlInterface
import com.eviware.soapui.model.iface.Operation
import com.eviware.soapui.impl.wsdl.WsdlOperation
import com.eviware.soapui.impl.wsdl.actions.*


def project = testRunner.testCase.testSuite.project
def ifaceList = project.getInterfaceList()

//Mise a jour de toutes les interfaces
ifaceList.each{
iface->
def url = iface.definition
log.info iface.getClass()
def oldName = iface.getName()
log.info "Début mise à jour de l'interface : " + iface.getName() + " avec url : " + url
try {
iface.updateDefinition( url, false)
}catch(exception){
log.error exception.description
}

log.info "Interface mise à jour"
iface.setName(oldName)
List<ModelItem> updated = new ArrayList<ModelItem>()
updated.addAll(recreateRequests(iface, true, false, true, false))
}

 

It works fine except that this doesn't take into account the environment i choose. It keeps updating with the same endpoint url and doesn't override it with my environment endpoint.

 

How can i modify this script to do an updateDefinition based on the environment ?

1 ACCEPTED SOLUTION

Accepted Solutions
Occasional Contributor

Re: Update definition with active environment

I managed to do what i want with the following code :

 

import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateRequests
import static com.eviware.soapui.impl.wsdl.actions.iface.UpdateInterfaceAction.recreateTestRequests
import com.eviware.soapui.model.ModelItem
import com.eviware.soapui.impl.wsdl.WsdlRequest
import com.eviware.soapui.model.iface.Request
import com.eviware.soapui.impl.wsdl.WsdlInterface
import com.eviware.soapui.model.iface.Operation
import com.eviware.soapui.impl.wsdl.WsdlOperation
import  com.eviware.soapui.impl.wsdl.actions.*

def project = testRunner.testCase.testSuite.project
def ifaceList = project.getInterfaceList()

//Mise a jour de toutes les interfaces
ifaceList.each{
	iface->
	//Recuperation de l'url du wsdl utilise pour la création du service
	def oldWsdlUrl = iface.definition
	//Récupération du nom du service SOAP
	def serviceName = iface.getName()
	//Debut de la MAJ de la definition du service
	log.info "Debut mise a jour du wsdl avec l'ancienne addresse : " + oldWsdlUrl 
	//recuperation du nouveau endpoint du service
	String newEnpointUrl = context.expand(project.getActiveEnvironment().getSoapServiceByName(serviceName).getEndpoint().getConfig().getStringValue());
	//Extraire domain du nouveau endpoint
	int slashslash = newEnpointUrl.indexOf("//") + 2;
	String newDomain = newEnpointUrl.substring(slashslash,newEnpointUrl.indexOf('/', slashslash));
	//Remplacer le domain du wsdl par le nouveau correspondant à l'environnement
	slashslash = oldWsdlUrl.indexOf("//") + 2;
	String newWsdlUrl = oldWsdlUrl.substring(0,slashslash) + newDomain + oldWsdlUrl.substring(oldWsdlUrl.indexOf('/', slashslash));
	//Mise a jour
	iface.updateDefinition( newWsdlUrl, false)
	//on force le renomage original
	iface.setName(serviceName)
	List<ModelItem> updated = new ArrayList<ModelItem>()
	updated.addAll(recreateRequests(iface, true, false, true, false))
	log.info "Fin de la mise a jour du wsdl  avec la nouvelle addresse  : " + newWsdlUrl
}

 

 

Thanks to @Nastya_Khovrina

13 REPLIES 13
Community Manager

Re: Update definition with active environment

Hi @ancm,

 

I guess this behavior (selecting an active environment) depends on how exactly you run a test. There are several ways of specifying the environment: on the ReadyAPI control bar or in the script. You can try adding the environment name in the script:

// Replace the project and environment names with those you need

def proj = testRunner.testCase.project.workspace.getProjectByName("Sample Project")
proj.setActiveEnvironment("Test Environment")
---------
Tanya Gorbunova
SmartBear Community Manager

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

Re: Update definition with active environment

Nothing changes with this piece of code

Community Manager

Re: Update definition with active environment

Hmmm. Community, we need your help.

@nmrao@msiadak@avidCoder ?

---------
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: Update definition with active environment

Sorry, can't go thru the code.

How about using Project level custom properties if something you got stuck with and like to proceed?


Regards,
Rao.
Occasional Contributor

Re: Update definition with active environment

In fact the whole purpose of this script is to perform an update definition of the service according to the chosen environment before running all tests.

 

The problem is that the url i get with "def url = iface.definition" is the one specified during the import of the soap project not the one corresponding to the environment.

 

I think What i need is to change the  definition URL according to the environment i choose before doing an update

 

image.png

 

I dont know if this is even possible to do it programmatically 

Community Hero

Re: Update definition with active environment

Just reading the statement "How can i modify this script to do an updateDefinition based on the environment ?" -

I believe that, wsdl definition will be same irrespective of environment except the url. Isn't it?


Regards,
Rao.
Occasional Contributor

Re: Update definition with active environment

Yes it is

Occasional Contributor

Re: Update definition with active environment

Nobody seems to have a solution i guess the product cannot do it

Moderator

Re: Update definition with active environment

Hi @ancm,

 

I've checked your code. When you define the following in your code:

def url = iface.definition 

you get the WSDL URL. Please see the screenshot:

 

ReadyAPI_2019-03-13_09-48-06.png

 

As @nmrao  said this URL doesn't depend on an environment. This URL is defined on a service level.

 

If you need to update the definition based on the currently selected environment, you need to change the "url" value in your code before doing this:

iface.updateDefinition( url, false)

Now, you're using the same URL.

 

You can get the Endpoint of the active environment with this code:

project.getActiveEnvironment().getSoapServiceByName("Test_serviceSoap").getEndpoint().getConfig().getStringValue()

Note: don't forget to change the Test_serviceSoap value in the script to your actual Service name:

 

ReadyAPI_2019-03-13_12-06-40.png


Anastasia
Customer Care Team


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

New Here?
Join us and watch the welcome video:
Watch the new interview
Top Kudoed Authors