Forum Discussion

suchindrac's avatar
suchindrac
Occasional Contributor
16 years ago

How to set testCase endpoints using Groovy Scripts?

Hi All,
          How do we set testCase Endpoints using Groovy Scripts?

          In soapui, this is visible as "Request URL" in the top
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hello,

    The easiest way to manage your endpoint via a Groovy script is probably by creating a TestCase Test Property for it and using a Property Expansion. For example, create a new Test Property in the TestCase named "endpoint" and set the actual endpoint of the request to ${#TestCase#endpoint} (if you will be using the same endpoint for other testcases you may wish to make it a property on TestSuite level or even Project level instead). To change this property in a Groovy TestStep use:


    testRunner.testCase.properties['endpoint'].setValue('new endpoint')



    Regards,
    Dain
    eviware.com
    • PramodYadav's avatar
      PramodYadav
      Contributor

      SmartBear_Suppo Wonder why no one gave Kudos to this reply yet. Here it goes :). Kudos !

       

      As an additional note. if you want to use the endpoint url from a parameter defined at say TestSuite level, just change the TestCase to TestSuite in the endpoint url space. Something like this:

       

      ${#TestSuite#sGetTxsEndPointUrl}   

       

      Where, GetTxsEndPointUrl is a custom property i created at TestSuite level. If all your requests now have this formula at end point Url, there is no need to set, reset urls at test step level. Hope this helps to others. 

       

      Cheers, Pramod

  • Buschfunk's avatar
    Buschfunk
    Frequent Contributor
    I'm using the following code to set the endpoint for a request:

    testRunner.testCase.getTestStepByName(requestName).getHttpRequest().setEndpoint(ENDPOINT)


    requestName:
    The name of the test request which endpoint you'd like to change.

    ENDPOINT:
    A string representing the new endpoint, e.g. "http://localhost"