Forum Discussion

kric's avatar
kric
New Contributor
7 years ago

SoapUI 5.4.0 query on setup script :dynamic endpoint url

Hi i want to place the endpoint url dynamically on the basis of test case name through setup script in SOAPUI 5.4.0 version. If I am having three test cases in a test suite ,Testcase-A and Testcase-b should run at one url and Testcase-C should run at different url ,I am using below code but its replacing all endpoint urls in all test cases. ----------------------- def result = com.eviware.soapui.support.UISupport.prompt("Please select the enviornment", "Environment", ['UAT_API','IT2','IT3','UAT1','UAT2','UAT3']) def testcases = testSuite.getTestCaseList() if(result == 'UAT1'){ testcases.each { testcase -> def teststeps = testcase.getTestStepList() teststeps.each { teststep -> teststep.setPropertyValue('endpoint','') } } }else if(result == 'UAT2'){ testcases.each { testcase -> def teststeps = testcase.getTestStepList() teststeps.each { teststep -> teststep.setPropertyValue('endpoint','') } } }else if(result == 'UAT3'){ testcases.each { testcase -> def teststeps = testcase.getTestStepList() teststeps.each { teststep -> teststep.setPropertyValue('endpoint','') } } }else if(result == 'UAT_API'){ testcases.each { testcase -> def teststeps = testcase.getTestStepList() teststeps.each { teststep -> teststep.setPropertyValue('endpoint','https://alpha-api.com') } } }else if(result == 'IT2'){ testcases.each { testcase -> def teststeps = testcase.getTestStepList() teststeps.each { teststep -> teststep.setPropertyValue('endpoint','https://it2-webservices.com:1') } } }else if(result == 'IT3'){ testcases.each { testcase -> def teststeps = testcase.getTestStepList() teststeps.each { teststep -> teststep.setPropertyValue('endpoint','') } } } ------------------------------- What is the solution for this.Can anyone help on this

  • Sorry, I misread. You were wanting to set the endpoint on each testStep in a testcase.

     

    Try:

    Map endpoints = [
        'UAT_API': [
            "http://foo",
            "http://bar"
        ],
        'IT2': [
            "http://foo2",
            "http://bar2"
         ],
        //...
    ]
    
    def result = com.eviware.soapui.support.UISupport.prompt("Please select the enviornment", "Environment", ['UAT_API','IT2','IT3','UAT1','UAT2','UAT3'])
    
    def cases = testSuite.getTestCaseList()
    cases[0].getTestStepList().each { step -> step.setPropertyValue("endpoint", endpoints[result][0]) }
    cases[1].getTestStepList().each { step -> step.setPropertyValue("endpoint", endpoints[result][0]) }
    cases[2].getTestStepList().each { step -> step.setPropertyValue("endpoint", endpoints[result][1]) }
    
  • JHunt's avatar
    JHunt
    Community Hero

    Try this:

    Map endpoints = [
        'UAT_API': [
    "http://foo",
    "http://bar"
    ], 'IT2': [
    "http://foo2",
    "http://bar2"
    ], //... ] def result = com.eviware.soapui.support.UISupport.prompt("Please select the enviornment", "Environment", ['UAT_API','IT2','IT3','UAT1','UAT2','UAT3']) Closure setTestCaseEndpoints = { tc -> def steps = tc.getTestStepList() steps[0].setPropertyValue("endpoint", endpoints[result][0]) steps[1].setPropertyValue("endpoint", endpoints[result][0]) steps[2].setPropertyValue("endpoint", endpoints[result][1]) } testSuite.getTestCaseList().each(setTestCaseEndpoints)

     

    • kric's avatar
      kric
      New Contributor

      Getting below exception:

      Cannot invoke method setPropertyValue() on null object

      • JHunt's avatar
        JHunt
        Community Hero

        Sorry, I misread. You were wanting to set the endpoint on each testStep in a testcase.

         

        Try:

        Map endpoints = [
            'UAT_API': [
                "http://foo",
                "http://bar"
            ],
            'IT2': [
                "http://foo2",
                "http://bar2"
             ],
            //...
        ]
        
        def result = com.eviware.soapui.support.UISupport.prompt("Please select the enviornment", "Environment", ['UAT_API','IT2','IT3','UAT1','UAT2','UAT3'])
        
        def cases = testSuite.getTestCaseList()
        cases[0].getTestStepList().each { step -> step.setPropertyValue("endpoint", endpoints[result][0]) }
        cases[1].getTestStepList().each { step -> step.setPropertyValue("endpoint", endpoints[result][0]) }
        cases[2].getTestStepList().each { step -> step.setPropertyValue("endpoint", endpoints[result][1]) }