Forum Discussion

garlapati99's avatar
garlapati99
Occasional Contributor
10 years ago

Need to Change the end point URL on selecting a value from UISupport.prompt value

Hi,

 

I need to set the end point URL for all my test cases with a property value which i set on test suite.

 

I ran the below script for selecting the value

result = UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT'])

 

Now after selecting how to change the end point URL for all the test cases.

 

Thanks,

 

  • Excellent, no problem :-)

     

    If you're happy please can you mark the solution as complete?

     

    Thanks,

    Rup

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    If you just have one TestCase and want to use 'result' to set the endpoint for all TestSteps in that TestCase, then you could:

     

    1) Add a Groovy TestStep before all the Request TestSteps. In the Groovy TestStep:

     

    //Set and store your result property / variable in the context object (available to all TestSteps in that TestCase)

    context["result"] = UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT'])

     

    2) In your Test Request TestStep:

     

    //Use a property expansion to set the endpoint to use the result property from the context object. The following syntax can be used to reference the result property from the context, replace the hardcoded edpoint URL text with this:

    ${result}

     

    To set the endpoint at TestSuite level e.g. so that all TestCases can see the result property. You need to set the result property against either the TestSuite or higher object e.g. Project or Global level. To do this for a TestSuite property

     

    In the Groovy TestStep, to set the TestSuite property with your captured endpoint, try something like:

     

    def endpoint = UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT'])

    testRunner.testCase.testSuite.setPropertyValue( "result", endpoint )

     

    And replace endpoint URLs in Request TestSteps with 

     

    ${#TestSuite#result}

     

    For more examples on setting properties etc see http://www.soapui.org/scripting---properties/tips---tricks.html

     

    See also

     

    http://www.soapui.org/scripting---properties/working-with-properties.html

    http://www.soapui.org/scripting---properties/property-expansion.html

     

    Hope this helps,

    Cheers,

    Rup

     

    • garlapati99's avatar
      garlapati99
      Occasional Contributor

      Hi, 

       

      Thanks for the reply, but what i am trying to do is, on the Test Case level

       

      I have set two properties

       

      SIT - https://10.91.35.41:37093/Services

      UAT - https://10.91.37.160:37093/Services

       

      Now on the Setup Script i am trying this

      UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT'])

       

      Now when i select the SIT in the drop down it has to take the SIT properties and run all the test steps.

       

      Thanks,

      Kalyan

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Hi Kalyan,

         

        Ok, no problem.

         

        So if I am understanding you right:

         

        1. you have a TestCase with two properties (SIT=... & UAT=...)
        2. The TestCase contains multiple Test Request TestSteps
        3. Depending on the prompt you want to set the endpoint URL of the Request TestSteps to the URL contained in either SIT pr UAT.

        So, in a Groovy TestStep how about:

         

        import com.eviware.soapui.support.UISupport

         

        //Conditionally set endpointURL based on result

        def result = UISupport.prompt("Please select the enviornment", "Environment", ['SIT', 'UAT'])
        if (result=='SIT') context["endpointURL"]=testRunner.testCase.getPropertyValue("SIT")
        else context["endpointURL"]=testRunner.testCase.getPropertyValue("UAT")

         

        //Just to check, print it out

        log.info context["endpointURL"]

         

        Then in the Request TestSteps, use a property expansion to insert the value of context["endpointURL"] into the endpoint URL box e.g. ${endpointURL}

         

        Is this what you wanted?

        Cheers,

        Rup