Forum Discussion

evenflow58's avatar
evenflow58
New Contributor
7 years ago
Solved

Get environment url in groovy script

Is there a way to get the url set for an environment in a groovy script?

  • To get the URL, you can use the following snippet. It's not pretty, but it works.

     

    def env = testRunner.testCase.testSuite.project.activeEnvironment;
    log.info(env);
    
    def proj = env.getSoapServiceCount().toInteger();
    
    for (int i = 0; i < proj; i++)
    {
    	def soap = env.getSoapServiceAt(i);
    	def config = soap.getEndpoint().config;
    	def endpoint = new XmlSlurper().parseText(config.toString());
    	log.info(endpoint);
    }
    

3 Replies

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      To get the URL, you can use the following snippet. It's not pretty, but it works.

       

      def env = testRunner.testCase.testSuite.project.activeEnvironment;
      log.info(env);
      
      def proj = env.getSoapServiceCount().toInteger();
      
      for (int i = 0; i < proj; i++)
      {
      	def soap = env.getSoapServiceAt(i);
      	def config = soap.getEndpoint().config;
      	def endpoint = new XmlSlurper().parseText(config.toString());
      	log.info(endpoint);
      }
      
      • evenflow58's avatar
        evenflow58
        New Contributor

        The only think I had to change was to use getRestServiceCount instead of getSoapServiceCount but otherwise this worked. Thanks.