cancel
Showing results for 
Search instead for 
Did you mean: 

how to get endpoint from default environment ?

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Moderator

Re: how to get endpoint from default environment ?

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. ⬇️⬇️⬇️

View solution in original post

3 REPLIES 3
Moderator

Re: how to get endpoint from default environment ?

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. ⬇️⬇️⬇️

View solution in original post

Frequent Contributor

Re: how to get endpoint from default environment ?

ok, thank you very much !  🙂

Moderator

Re: how to get endpoint from default environment ?

You're welcome!



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:
Announcements
Top Kudoed Authors