【问题标题】:How can we add SOAP request Test step in a Test Case using groovy scripts我们如何使用 groovy 脚本在测试用例中添加 SOAP 请求测试步骤
【发布时间】:2016-02-23 08:20:26
【问题描述】:

我正在寻找在测试用例中添加一个 SOAP 请求测试步骤,来自不同的 TestSuite 和测试用例,我已经编写了该部分以添加 Groovy 脚本以满足相同的要求,但无法添加 SOAP 请求测试步骤。有什么帮助吗?

以下是我的代码:

import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory

suite = context.testCase.testSuite.project.addNewTestSuite("AutomatedTestSuite")
tc = suite.addNewTestCase("automatedTestCase")
gs = tc.addTestStep( GroovyScriptStepFactory.GROOVY_TYPE, "GroovyScript1" )
gs2 = tc.addTestStep( GroovyScriptStepFactory.GROOVY_TYPE, "GroovyScript3" )
gs.properties["script"].value = 'log.info(\'hello world\')'

【问题讨论】:

    标签: groovy soapui


    【解决方案1】:

    您可以通过项目的名称获取另一个testSuite,testCase和testStep,如下所示:

    def project = context.testCase.testSuite.project
    def testStep = project.testSuites['TestSuiteName'].testCases['TestCaseName'].testSteps['testStepName']
    

    或者使用getXXXXbyName方法代替数组方法:

    def testStep = project.getTestSuiteByName('TestSuiteName').getTestCaseByName('TestCaseName').getTestStepByName('testStepName')
    

    然后要将此 testStep 添加到您的 testCase 中,您可以使用 cloneStep(WsdlTestStep testStep, String name) 方法。

    全部在你的脚本中:

    def suite = context.testCase.testSuite.project.addNewTestSuite("AutomatedTestSuite")
    def tc = suite.addNewTestCase("automatedTestCase")
    
    // get desired testStep
    def project = context.testCase.testSuite.project
    def testStep = project.testSuites['TestSuiteName'].testCases['TestCaseName'].testSteps['testStepName']
    // add it to your new generated testCase
    tc.cloneStep(testStep,testStep.name + "_Copy")
    

    根据评论进行编辑

    如果您想创建一个新的而不是另一个 SOAP testStep 的副本,则可以使用以下代码来完成。考虑到创建 SOAP 类型的 testStep 需要比创建 groovy 时更多的信息,因为需要 wsdl 操作信息(在示例中,我们采用第一个,但如果你有多个照顾你拿什么)。

    IMO 第一种方法更简单,你可以复制另一个 testStep 并更改你想要的属性......无论如何,如果你想在这里这样做,你是:

    import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
    def suite = context.testCase.testSuite.project.addNewTestSuite("AutomatedTestSuite")
    def tc = suite.addNewTestCase("automatedTestCase")
    
    // get the WSDL operation... for the example we take the first one
    // however if you've more get the correct one
    def operation = testRunner.testCase.testSuite.project.getInterfaceAt(0).getOperationList()[0]
    // factory to create the testStepConfig
    def factory = new WsdlTestRequestStepFactory()
    def config = factory.createConfig(operation,'stepName') 
    // create the testStep
    def testStep = tc.addTestStep(config)
    // change the request
    testStep.properties['Request'].value = '<request>someData</request>'
    

    希望对你有帮助,

    【讨论】:

    • 我还有一个问题@albcliff 是否有任何其他方式获得项目参考。我的意思是而不是 def project = context.testCase.testSuite.project
    • 另外克隆不是我想要的,我需要从我的一个测试套件中的另一个测试套件中添加一个新的测试步骤,并且在该测试步骤中应该是 SOAP 请求,就像我添加了 groovy 脚本测试进入m代码
    • @Manoj 您可以使用testRunnercontext 获取project 的方式相同,但我认为您要求的是更紧凑的方式......在一个时髦的测试中认为没有……至少我不知道怎么做。
    • @Manoj 鄙视方法的名称 cloneStep,它确实创建了 testStep 的副本,我打算使用此解决方案,因为在问题中您似乎想从另一个 testSuite 复制请求而不是创建新的请求。此外,添加新的 testStep 很难做到,因为您需要更多信息(端点、来自 wsdl 的方法...)并执行更多步骤...
    猜你喜欢
    • 1970-01-01
    • 2018-05-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-09
    • 1970-01-01
    相关资源
    最近更新 更多