Forum Discussion

evenflow58's avatar
evenflow58
New Contributor
8 years ago

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);
    }
    
    • groovyguy's avatar
      groovyguy
      Community Hero

      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.