Forum Discussion

krogold's avatar
krogold
Regular Contributor
6 years ago

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 ?

 

 

 

  • 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)
         }
  • Nastya_Khovrina's avatar
    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)
         }