运行 另一个测试用例,循环遍历属性 (getValues &SetValues) - Groovy 脚本
Running Another TestCases, looping through Properties (getValues &SetValues) - Groovy Script
如何使用 TestCase S_TC_Addition 中的 TestStep“LIST”值获取所有属性(列表中只有 2 个或 100 个无关紧要)并将它们设置在 TestStep 上TestCase M_TC_Add 中的“LIST”,然后从 TestCase M_TC_Add 中的 TestStep“EXIT”获取所有属性和值,并将它们设置在 TestCase S_TC_Addition 中的 TestStep“EXIT”,在 groovy 脚本(在本例中为 EXECUTION_Addition)?
目前我有这个(它只获取和设置我手动指示“FirstValue”、“SecondValue”的属性):
import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.wsdl.testcase.*
import com.eviware.soapui.model.testsuite.*
//Locating TestCase in different project
def projectName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("PROJECT_NAME")
def testSuitetName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("TEST_SUITE_NAME")
def testCaseName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("TEST_CASE_NAME")
//Getting only two properties from the "LIST" TestStep in S_TC_Addition TestCase
def firstNumber = testRunner.testCase.getTestStepByName("LIST").getPropertyValue("FirstValue")
def secondNumber = testRunner.testCase.getTestStepByName("LIST").getPropertyValue("SecondValue");
//Setting only two properties on the "LIST" TestStep in M_TC_Add TestCase
def passFirst = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("FirstValue", firstNumber);
def passSecond = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("SecondValue", secondNumber);
//Running TestCase in different project
testCaseToRun = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).testSuites[testSuitetName].testCases[testCaseName]
testCaseToRun.run(null,false)
//Getting one property from the "EXIT" TestStep in M_TC_Add TestCase
def getAdditionResult = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("EXIT").getPropertyValue("additionResult");
//Setting only one property on the "EXIT" TestStep in S_TC_Addition TestCase
testRunner.testCase.testSteps["EXIT"].setPropertyValue( "additionResult", getAdditionResult);
如果您要查找某个对象的 properties/methods,请始终使用类似 :
的内容
println (obj.getClass())
你的情况println( testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getClass() )
这将为您提供 class 与您一起工作的名字
然后在互联网上搜索javadoc your.class.name
,它应该会给你这样的参考:
https://www.soapui.org/apidocs/5.5.0/com/eviware/soapui/model/TestPropertyHolder.html
对于您的情况,您可以获得测试步骤的所有属性:
List props = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyList()
props.each{ p->
println( "${p.getName()} = ${p.getValue()}" )
}
这就是我想要实现的目标 :) 感谢 daggett :)
//Get all properties from current TestCase's TestStep "LIST" and transfer them to indicated TestCase in code above, and set them in TestStep "LIST"
def ListProperties = testRunner.testCase.getTestStepByName("LIST").getPropertyList()
ListProperties.each{ lp->
passPropertiesToList = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("${lp.getName()}", "${lp.getValue()}");
}
//Get all properties from current TestCase and transfer them to indicated TestCase in code above
def exitProperties = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("EXIT").getPropertyList()
exitProperties.each{ ep->
passPropertiesToExit = testRunner.testCase.testSteps["EXIT"].setPropertyValue("${ep.getName()}", "${ep.getValue()}");
}
如何使用 TestCase S_TC_Addition 中的 TestStep“LIST”值获取所有属性(列表中只有 2 个或 100 个无关紧要)并将它们设置在 TestStep 上TestCase M_TC_Add 中的“LIST”,然后从 TestCase M_TC_Add 中的 TestStep“EXIT”获取所有属性和值,并将它们设置在 TestCase S_TC_Addition 中的 TestStep“EXIT”,在 groovy 脚本(在本例中为 EXECUTION_Addition)?
目前我有这个(它只获取和设置我手动指示“FirstValue”、“SecondValue”的属性):
import com.eviware.soapui.impl.wsdl.*
import com.eviware.soapui.impl.wsdl.testcase.*
import com.eviware.soapui.model.testsuite.*
//Locating TestCase in different project
def projectName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("PROJECT_NAME")
def testSuitetName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("TEST_SUITE_NAME")
def testCaseName = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyValue("TEST_CASE_NAME")
//Getting only two properties from the "LIST" TestStep in S_TC_Addition TestCase
def firstNumber = testRunner.testCase.getTestStepByName("LIST").getPropertyValue("FirstValue")
def secondNumber = testRunner.testCase.getTestStepByName("LIST").getPropertyValue("SecondValue");
//Setting only two properties on the "LIST" TestStep in M_TC_Add TestCase
def passFirst = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("FirstValue", firstNumber);
def passSecond = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("SecondValue", secondNumber);
//Running TestCase in different project
testCaseToRun = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).testSuites[testSuitetName].testCases[testCaseName]
testCaseToRun.run(null,false)
//Getting one property from the "EXIT" TestStep in M_TC_Add TestCase
def getAdditionResult = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("EXIT").getPropertyValue("additionResult");
//Setting only one property on the "EXIT" TestStep in S_TC_Addition TestCase
testRunner.testCase.testSteps["EXIT"].setPropertyValue( "additionResult", getAdditionResult);
如果您要查找某个对象的 properties/methods,请始终使用类似 :
的内容println (obj.getClass())
你的情况println( testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getClass() )
这将为您提供 class 与您一起工作的名字
然后在互联网上搜索javadoc your.class.name
,它应该会给你这样的参考:
https://www.soapui.org/apidocs/5.5.0/com/eviware/soapui/model/TestPropertyHolder.html
对于您的情况,您可以获得测试步骤的所有属性:
List props = testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getPropertyList()
props.each{ p->
println( "${p.getName()} = ${p.getValue()}" )
}
这就是我想要实现的目标 :) 感谢 daggett :)
//Get all properties from current TestCase's TestStep "LIST" and transfer them to indicated TestCase in code above, and set them in TestStep "LIST"
def ListProperties = testRunner.testCase.getTestStepByName("LIST").getPropertyList()
ListProperties.each{ lp->
passPropertiesToList = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("LIST").setPropertyValue("${lp.getName()}", "${lp.getValue()}");
}
//Get all properties from current TestCase and transfer them to indicated TestCase in code above
def exitProperties = testRunner.testCase.testSuite.project.workspace.getProjectByName(projectName).getTestSuiteByName(testSuitetName).getTestCaseByName(testCaseName).getTestStepByName("EXIT").getPropertyList()
exitProperties.each{ ep->
passPropertiesToExit = testRunner.testCase.testSteps["EXIT"].setPropertyValue("${ep.getName()}", "${ep.getValue()}");
}