2

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

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

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

谢谢,马丹

4

2 回答 2

1

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

另一种方法是设置属性并以编程方式运行 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);
于 2013-08-13T06:36:01.047 回答
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())
}
于 2014-07-09T02:18:02.567 回答