Ask a Question

how to get endpoint from default environment ?

SOLVED
krogold
Regular Contributor

how to get endpoint from default environment ?

Hello,

I'm able to get endpoint from my project's active environment, using the following :

def env = testRunner.testCase.testSuite.project.activeEnvironment

log.info("Active Environment: " + env.name)

rest = testRunner.testCase.testSuite.project.activeEnvironment.getRestServiceAt(0)
config = rest.getEndpoint().config
endpoint = new XmlSlurper().parseText(config.toString())

The problem is when this environment is the default one. it seems that it does not handle the getrestServiceAt method, so I cannot determine which endpoint it uses (from experimentation it seems that it uses the one stated in the swagger)

Is there a possibility to get it programmatically ?

 

 

 

3 REPLIES 3
Nastya_Khovrina
SmartBear Alumni (Retired)

Hi @krogold,

 

You cannot get an endpoint of the default environment because there is no common endpoint. You can configure a new endpoint for every test step even if they were created based on the same service. Please see my sample video: https://1drv.ms/u/s!AnCx6DcSb33_nXgxTD4Kvm33FpGQ

 

In case of the Default environment, you may want to get a service endpoint or an endpoint of a particular test step. Here is the script to get the service endpoint:

def project = context.getTestCase().getTestSuite().getProject();
def endpoint = project.getInterfaceAt(0).getEndpoints().toString()
log.info("Service endpoint: " + endpoint)

 

If you want to do this on one Groovy test step, you can use the following script: 

def env = testRunner.testCase.testSuite.project.activeEnvironment

log.info("Active Environment: " + env.name)

if (env.name!="Default environment") {
rest = testRunner.testCase.testSuite.project.activeEnvironment.getRestServiceAt(0)
config = rest.getEndpoint().config
envEndpoint = new XmlSlurper().parseText(config.toString())
log.info("Environment endpoint: " + envEndpoint)
}
else { 	def project = context.getTestCase().getTestSuite().getProject();
     def endpoint = project.getInterfaceAt(0).getEndpoints().toString()
     log.info("Service endpoint: " + endpoint)
     }

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

ok, thank you very much !  🙂

Nastya_Khovrina
SmartBear Alumni (Retired)

You're welcome!


Did my reply answer your question? Give Kudos or Accept it as a Solution to help others. ⬇️⬇️⬇️
cancel
Showing results for 
Search instead for 
Did you mean: