0

我想编写一个在请求中设置输入的 groovy 脚本。当 groovy 在同一个测试套件中执行时它工作正常,但我希望这个脚本通过几个测试套件。这是我的代码,为了测试,我得到了第 5 个测试套件、第一个测试用例和第一个测试步骤。它是 getXmlHolder 行失败并出现“意外的 CDATA”错误。我试图将 testSuite 和 testCase 添加到 inputHolder 字符串中,但这也无济于事。

def groovyUtils = new com.eviware.soapui.support.GroovyUtils( context ) 

def project = context.testCase.testSuite.project

    def testSuite = project.getTestSuiteAt(5)
    log.info(testSuite.getLabel())
    def testCase = testSuite.getTestCaseAt(0)
    log.info(testCase.getLabel())
    def testStep = testCase.getTestStepAt(0)
    log.info(testStep.getLabel())

    def teststepname = testCase.getTestStepAt(0).getName().toString() 
    def inputHolder = +teststepname + "#Request"
    log.info(inputHolder);
    def holderRawReq = groovyUtils.getXmlHolder(inputHolder)
    holderRawReq["//tem:brandId"] = "test"

我认为 getXmlHolder 只检查它所在的 testSuite,所以问题是如何让它访问其他 testSuite?

4

1 回答 1

3

好的,解决了。

您必须为您当前所在的 testStep 创建一个上下文,如下所示:

import com.eviware.soapui.impl.wsdl.teststeps.*

def project = context.testCase.testSuite.project
def testSuite = project.getTestSuiteAt(5)
def testCase = testSuite.getTestCaseAt(1)
def testStep = testCase.getTestStepAt(1)

// this will get the current teststep name
def teststepname = testStep.getName().toString() 

//create a context for the teststep where we are
def testStepContext = new com.eviware.soapui.impl.wsdl.testcase.WsdlTestRunContext(testStep);

//create a util on the testStepContext
def groovyUtils = new com.eviware.soapui.support.GroovyUtils( testStepContext ) 

def inputHolder = teststepname + "#Request"
def holderRawReq = groovyUtils.getXmlHolder(inputHolder)

holderRawReq["//tem:brandId"] = "test7"
holderRawReq.updateProperty()
于 2013-07-08T13:48:00.317 回答