【问题标题】:Dynamically setting input in SOAPUI requests with Groovy使用 Groovy 在 SOAPUI 请求中动态设置输入
【发布时间】:2013-07-05 13:25:59
【问题描述】:

我想编写一个在请求中设置输入的 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?

【问题讨论】:

    标签: groovy soapui test-suite


    【解决方案1】:

    好的,解决了。

    您必须为您当前所在的 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()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多