动态修改所有的endpoint (Dynamically update all endpoint in each test suite with properties file)

1. 选择自己的project,在'Project Properties'中将'Resource Root'设置为'${projectDir}'

2. 在project同目录下创建mockServices.properties文件,并定义MY_ENDPOINT=http://x.x.x.x:port/webservice

3. 将下边的代码放在project的'Load Script'中

4. 重新加载project

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context)
def projectDir = groovyUtils.projectPath

def myProperties = new java.util.Properties();
myProperties.load(new FileInputStream(projectDir+"/mockServices.properties"));

def myEndpoint = myProperties["MY_ENDPOINT"]
log.info(myEndpoint)
/*
 @Author : Pradeep Bishnoi
 @Description : Setting my customized endpoint URL
@Usage : Place the script in the Project Load/Save script section
*/

 testSuiteList = project.getTestSuites()
 log.info(testSuiteList)
 text = "~"
 testSuiteList.each
 {
 testSuite = project.getTestSuiteByName(it.key)
 testCaseList = testSuite.getTestCases()
 log.info " ${text*5} TestSuite :: $testSuite.name"
 testCaseList.each
  {
  testCase = testSuite.getTestCaseByName(it.key)
  log.info " ${text*5} Testcase :: $testCase.name"
 
  wsdlTestSteps = testCase.getTestStepsOfType( com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep.class )  //only WsdlTestRequest steps
  wsdlTestSteps.each
   {
   //log.info it.properties['Endpoint'].value
   it.properties['Endpoint'].value = myEndpoint
   }
  }
 }
 
log.info "All the endpoints are now : $myEndpoint"
原文地址:https://www.cnblogs.com/z1500592/p/6022692.html