【问题标题】:Running Another TestCases, looping through Properties (getValues &SetValues) - Groovy Script运行另一个测试用例,循环遍历属性(getValues &SetValues) - Groovy 脚本
【发布时间】:2021-08-29 08:54:02
【问题描述】:

如何从 TestCase S_TC_Addition 的 TestStep “LIST” 中获取所有属性(列表中只有 2 个或 100 个无关紧要),并将它们设置在 TestCase M_TC_Add 中的 TestStep “LIST” 中, 然后,从 TestCase M_TC_Add 中的 TestStep “EXIT” 中获取所有属性和值,并在 groovy 脚本(在本例中为 EXECUTION_Addition)中的 TestCase S_TC_Addition 中的 TestStep “EXIT” 上设置它们?

目前我有这个(它只获取和设置我手动指示“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);

【问题讨论】:

  • 这么多字...问题出在哪里?
  • @daggett 问题是我如何从一个测试用例(S_TC_Addition)获取所有具有值(来自 testStep LIST)的属性,并使用 groovy 脚本将它们设置在另一个测试用例(M_TC_Add)的列表中
  • 请编辑问题并将此信息放在那里。所以,每个人都清楚。
  • @daggett 希望现在更容易理解

标签: rest groovy soap soapui


【解决方案1】:

如果你正在寻找某个对象的属性/方法,那么总是使用类似的东西:

println (obj.getClass())

在你的情况下println( testRunner.testCase.getTestStepByName("TRACING_TC_Addition").getClass() )

这将为您提供您正在使用的班级的名称

然后在互联网上搜索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()}" )
}

【讨论】:

    【解决方案2】:

    这就是我想要实现的目标 :) 感谢 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()}");
    }
    

    【讨论】:

      猜你喜欢
      • 2018-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多