您可以通过项目的名称获取另一个testSuite,testCase和testStep,如下所示:
def project = context.testCase.testSuite.project
def testStep = project.testSuites['TestSuiteName'].testCases['TestCaseName'].testSteps['testStepName']
或者使用getXXXXbyName方法代替数组方法:
def testStep = project.getTestSuiteByName('TestSuiteName').getTestCaseByName('TestCaseName').getTestStepByName('testStepName')
然后要将此 testStep 添加到您的 testCase 中,您可以使用 cloneStep(WsdlTestStep testStep, String name) 方法。
全部在你的脚本中:
def suite = context.testCase.testSuite.project.addNewTestSuite("AutomatedTestSuite")
def tc = suite.addNewTestCase("automatedTestCase")
// get desired testStep
def project = context.testCase.testSuite.project
def testStep = project.testSuites['TestSuiteName'].testCases['TestCaseName'].testSteps['testStepName']
// add it to your new generated testCase
tc.cloneStep(testStep,testStep.name + "_Copy")
根据评论进行编辑
如果您想创建一个新的而不是另一个 SOAP testStep 的副本,则可以使用以下代码来完成。考虑到创建 SOAP 类型的 testStep 需要比创建 groovy 时更多的信息,因为需要 wsdl 操作信息(在示例中,我们采用第一个,但如果你有多个照顾你拿什么)。
IMO 第一种方法更简单,你可以复制另一个 testStep 并更改你想要的属性......无论如何,如果你想在这里这样做,你是:
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
def suite = context.testCase.testSuite.project.addNewTestSuite("AutomatedTestSuite")
def tc = suite.addNewTestCase("automatedTestCase")
// get the WSDL operation... for the example we take the first one
// however if you've more get the correct one
def operation = testRunner.testCase.testSuite.project.getInterfaceAt(0).getOperationList()[0]
// factory to create the testStepConfig
def factory = new WsdlTestRequestStepFactory()
def config = factory.createConfig(operation,'stepName')
// create the testStep
def testStep = tc.addTestStep(config)
// change the request
testStep.properties['Request'].value = '<request>someData</request>'
希望对你有帮助,