Update definition with active environment
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi ancm,
This might not be fully correspond to what you are trying to do, but perhaps it might help you in one way or the other to guide you in some direction...
I have some urls that I want to adapt depending on the environment I currently am running. For that I run following line of code in a groovy test step:
def url = new Urls(testRunner).GetEnvUrl() testRunner.testCase.testSuite.project.setPropertyValue("url", url)
The first line is a link to my script library that does this:
import com.eviware.soapui.model.testsuite.TestRunner public class Urls { // Properties def testRunner; // Constructor Urls(TestRunner testRunner) { this.testRunner = testRunner; } // Methods def GetEnvUrl() { def env = testRunner.testCase.testSuite.project.activeEnvironment.name def url switch (env) { case "DEV_AZ": url = "https://mydesiredurl.azurewebsites.net/api/v1/" break; case "TEST_AZ": url = "https://api.testaz.mydesiredurl.com/api/v1/" break case "BETA_AZ": url = "https://api.betaaz.mydesiredurl.com/api/v1/" break; case "TNI_AZ": url = "https://api.tniaz.mydesiredurl.com/api/v1/" break; case "DEV": url = "https://api.dev.mydesiredurl.com/api/v1/" break; case "TEST": url = "https://test.api.mydesiredurl.com/api/v1/" break; case "BETA": url = "https://beta.api.mydesiredurl.com/api/v1/" break; case "TNI": url = "https://tni.api.mydesiredurl.com/api/v1/" break; case "STAGING": url = "https://staging.api.mydesiredurl.com/api/v1/" break; case "PROD": url = "https://prod.api.mydesiredurl.com/api/v1/" break; } return url; } }
I can now re-use this "url" (either directly in the same script or by using the context.expand from the project property "url") to define dynamicly some of the properties I use to assert against. For instance:
def agentid = context.expand( '${agent#Response#$[\'member\'][0][\'agentId\']}' ) testRunner.testCase.testSuite.project.setPropertyValue ("agentidurl",url+"org/"+agentid)
So if I am running BETA I will get : "https://beta.api.mydesiredurl.com/api/v1/org/agendtid123", if I am running TNI "https://tni.api.mydesiredurl.com/api/v1/org/agendtid123" etc. For each environment I run my tests, my assertions will validate against the correct agintid expected value.
I now remember that I wanted to execute a JSON Schema Compliance assertion depending on the environment (as by default, this is an environment depending check). I can make this schema url dynamic by doing this:
testRunner.testCase.testSuite.project.setPropertyValue("swaggerSchameUrl",url+"swagger/v1/swagger.json")
But currently this assertion check (see below screen from v SOAPui PRO 2.5) does not allow to be build dynamicly. Perhaps there is some way to convert this JSON Schema Compliance assertion into a groovy script, but I haven't delved into that any deeper (and probably would not help your problem very much).
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Almost what i need except that i need wsdl address and no endpoint to be able to call iface.updateDefinition( url, false)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for sharing the solution with us, @ancm!
Tanya Yatskovskaya
SmartBear Community and Education Manager

- « Previous
-
- 1
- 2
- Next »
- « Previous
-
- 1
- 2
- Next »