使用groovy将TestStep从一个测试用例克隆到另一个测试用例

使用groovy将TestStep从一个测试用例克隆到另一个测试用例,groovy,soapui,Groovy,Soapui,我在测试套件中使用groovy脚本来填补自动化方面的空白。在这里,我需要将一个属性从一个测试用例克隆到另一个测试用例。例如将属性测试步骤从TestCase1克隆到TestCase2,以便从该属性获取值 我试图从一个TC到另一个TC获取属性中的值,但SOAPUI不允许执行该操作。我们无法将属性值从一个TC传输到另一个TC。因此,我开始使用groovy克隆测试步骤 非常感谢你的帮助。。等待任何人的答复 谢谢, Madhan您可以使用测试步骤“RunTestCase”从TestCase1运行TestC

我在测试套件中使用groovy脚本来填补自动化方面的空白。在这里,我需要将一个属性从一个测试用例克隆到另一个测试用例。例如将属性测试步骤从TestCase1克隆到TestCase2,以便从该属性获取值

我试图从一个TC到另一个TC获取属性中的值,但SOAPUI不允许执行该操作。我们无法将属性值从一个TC传输到另一个TC。因此,我开始使用groovy克隆测试步骤

非常感谢你的帮助。。等待任何人的答复

谢谢,
Madhan

您可以使用测试步骤“RunTestCase”从TestCase1运行TestCase2。在TestCase2中直接创建所需的属性,以便可以通过TestCase1中的“属性转移”测试步骤进行设置。有关运行测试用例和属性转移的更多信息

另一种方法是设置属性并以编程方式运行TestCase。大概是这样的:

// get properties from testCase, testSuite or project if you need
def testCaseProperty = testRunner.testCase.getPropertyValue( "MyProp" )
def testSuiteProperty = testRunner.testCase.testSuite.getPropertyValue( "MyProp" )
def projectProperty = testRunner.testCase.testSuite.project.getPropertyValue( "MyProp" )
def globalProperty = com.eviware.soapui.SoapUI.globalProperties.getPropertyValue( "MyProp" )

//get test case from other project or from the same one
project = testRunner.getTestCase().getTestSuite().getProject().getWorkspace().getProjectByName(project_name)
testSuite = project.getTestSuiteByName(suite_name);
testCase = testSuite.getTestCaseByName(testcase_name);

//set properties if you need
testRunner.testCase.setPropertyValue(property_name, property_value);
testRunner.testCase.setPropertyValue(another_property_name, another_property_value);

// run test case
runner = testCase.run(new com.eviware.soapui.support.types.StringToObjectMap(), false);

以下示例将测试套件中的所有属性复制到该测试套件所属的项目中

类似的机制可用于测试用例属性等

testSuite.getProperties().each {
    testSuite.getProject().setPropertyValue(it.getKey(), testSuite.getPropertyValue(it.getKey()))
}
从一个测试用例复制到另一个(我将留下定义测试用例)


非常感谢Artem,我使用上面的grrovy代码,它工作得非常好。事实上,我想得到那个财产的价值,我就这样使用它//如果需要targetStep=testCase.getTestStepByName(“客户”)custID=targetStep.getPropertyValue(“CustID1”)log.info custID,请获取属性
def sourceTestCase = youdefinethis
def destTestCase = youdefinethis
sourceTestCase.getProperties().each {
    destTestCase.setPropertyValue(it.getKey(), sourceTestCase.getPropertyValue(it.getKey())
}