groovy - 我们如何使用 groovy 脚本在测试用例中添加 SOAP 请求测试步骤

标签 groovy soapui

我正在寻找在测试用例中添加 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\')'

最佳答案

您可以通过项目的名称获取另一个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 添加到您的测试用例中,您可以使用 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 类型的 testStep 需要更多信息,因为需要 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>'

希望对你有帮助

关于groovy - 我们如何使用 groovy 脚本在测试用例中添加 SOAP 请求测试步骤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35572266/

相关文章:

grails - Grails:将BufferedImage写入响应

soapui - Windows 系统中的 SOAP UI 错误

grails - 如何通过模拟对象并期望一些预期结果来编写Spock单元测试

hibernate - 如何基于id更新一行(grails域类)?

Jenkins Pipeline 执行一个闭包(如 "parallel"步骤)

jenkins - 每次在 CLI - SOAPUI 中运行测试运行程序脚本时,如何将报告保存到新位置

xpath - SoapUI属性传输和XPath/XQuery数字格式

java - 在 Eval () 中执行 toString() - Groovy(Gstring 中的方法调用)

java - SoapUI SLF4J : Failed to load class “org.slf4j.impl.StaticLoggerBinder”

java - 在 groovy 脚本 (soapui) 中导入 jar 时出错