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

时间:2013-08-12 14:07:27

标签: groovy soapui

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

我试图将属性中的值从一个TC获取到另一个TC,但SOAPUI不允许执行该操作。我们不能将属性值从一个TC转移到另一个TC。所以我使用groovy来克隆测试步骤。

非常感谢您的帮助..等待任何人的回复..

谢谢, Madhan

2 个答案:

答案 0 :(得分:1)

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

另一种方法是设置属性并以编程方式运行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);

答案 1 :(得分:0)

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

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

testSuite.getProperties().each {
    testSuite.getProject().setPropertyValue(it.getKey(), testSuite.getPropertyValue(it.getKey()))
}

从一个测试用例复制到另一个测试用例(我将保留定义测试用例)

def sourceTestCase = youdefinethis
def destTestCase = youdefinethis
sourceTestCase.getProperties().each {
    destTestCase.setPropertyValue(it.getKey(), sourceTestCase.getPropertyValue(it.getKey())
}