Forum Discussion

raiqee's avatar
raiqee
Occasional Contributor
6 years ago

How to change SoapUI Endpoint with different Port?

Given I have one Endpoint but multiple Ports, how can I set it in SoapUI like Custom Property

e.g htts://10.1.10.101:{port}/

  • Hi Raiqee,

     

    You can use following code to set the port:-

    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port", "80")
    def port =  testRunner.testCase.testSteps["Properties"].getPropertyValue("Port");
    
    def endPointUrl = testRunner.testCase.getTestStepByName("REST Service Name").getHttpRequest().getEndpoint();
    
    String endpointPort = endPointUrl+":"+port
    
    log.info endpointPort
    

    If you have multiple ports use for loop to set it.

    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port", "80")
    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port1", "81")
    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port2", "82")
    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port3", "83")
    
    def data = context.testCase.getTestStepByName("Properties");
    String[] prop = new String[data.getPropertyCount()];
    prop = data.getPropertyNames();
    
    for ( int i = 0 ; i < prop.size(); i++ ){
    
    def port =  testRunner.testCase.testSteps["Properties"].getPropertyValue(prop[i]);
    
    def endPointUrl = testRunner.testCase.getTestStepByName("REST Service Name").getHttpRequest().getEndpoint();
    
    String endpointPort = endPointUrl+":"+port
    
    log.info endpointPort
    }

    Hope, this solution helps you out.

  • avidCoder's avatar
    avidCoder
    Super Contributor

    Hi Raiqee,

     

    You can use following code to set the port:-

    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port", "80")
    def port =  testRunner.testCase.testSteps["Properties"].getPropertyValue("Port");
    
    def endPointUrl = testRunner.testCase.getTestStepByName("REST Service Name").getHttpRequest().getEndpoint();
    
    String endpointPort = endPointUrl+":"+port
    
    log.info endpointPort
    

    If you have multiple ports use for loop to set it.

    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port", "80")
    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port1", "81")
    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port2", "82")
    testRunner.testCase.getTestStepByName("Properties").setPropertyValue("Port3", "83")
    
    def data = context.testCase.getTestStepByName("Properties");
    String[] prop = new String[data.getPropertyCount()];
    prop = data.getPropertyNames();
    
    for ( int i = 0 ; i < prop.size(); i++ ){
    
    def port =  testRunner.testCase.testSteps["Properties"].getPropertyValue(prop[i]);
    
    def endPointUrl = testRunner.testCase.getTestStepByName("REST Service Name").getHttpRequest().getEndpoint();
    
    String endpointPort = endPointUrl+":"+port
    
    log.info endpointPort
    }

    Hope, this solution helps you out.

    • nmrao's avatar
      nmrao
      Champion Level 3
      And where this script should be placed?