Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/extjs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用groovy脚本在测试用例中添加SOAP请求测试步骤_Groovy_Soapui - Fatal编程技术网

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

如何使用groovy脚本在测试用例中添加SOAP请求测试步骤,groovy,soapui,Groovy,Soapui,我正在寻找在一个测试用例中添加一个SOAP请求测试步骤,从不同的测试套件和测试用例中,我已经编写了为相同的需求添加Groovy脚本的部分,但无法添加SOAP请求测试步骤。有什么帮助吗 以下是我的代码: import com.eviware.soapui.impl.wsdl.teststeps.registry.GroovyScriptStepFactory suite = context.testCase.testSuite.project.addNewTestSuite("Automated

我正在寻找在一个测试用例中添加一个SOAP请求测试步骤,从不同的测试套件和测试用例中,我已经编写了为相同的需求添加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']
或者使用
getxxbyname
方法代替数组方法:

def testStep = project.getTestSuiteByName('TestSuiteName').getTestCaseByName('TestCaseName').getTestStepByName('testStepName')
然后,要将这个测试步骤添加到您的测试用例中,您可以使用方法

在您的脚本中:

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测试步骤,而不是另一个SOAP测试步骤的副本,则可以使用以下代码进行创建。考虑到创建SOAP类型的testStep需要比创建groovy类型的testStep更多的信息,因为需要wsdl操作信息(在本例中,我们使用第一个操作信息,但如果您有多个操作,请注意所使用的操作)

在我看来,第一种方法更简单,您可以复制另一个测试步骤并更改所需的属性。。。无论如何,如果你想这样做,你可以:

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>'
import com.eviware.soapui.impl.wsdl.teststeps.registry.WsdlTestRequestStepFactory
def suite=context.testCase.testSuite.project.addNewTestSuite(“AutomatedTestSuite”)
def tc=suite.addNewTestCase(“automatedTestCase”)
//获取WSDL操作。。。我们以第一个为例
//然而,如果你有更多的选择,那就选择正确的
def operation=testRunner.testCase.testSuite.project.getInterfaceAt(0.getOperationList()[0]
//工厂创建testStepConfig
def工厂=新的WsdlTestRequestStepFactory()
def config=factory.createConfig(操作,'stepName')
//创建测试步骤
def testStep=tc.addTestStep(配置)
//更改请求
testStep.properties['Request'].value='someData'

希望能有所帮助,

我还有一个问题@albcliff是否有其他方法获得项目参考。我的意思是,除了def project=context.testCase.testSuite.project之外,克隆也不是我想要的,我需要在我的一个测试套件中的另一个测试套件中添加一个新的测试步骤,该测试步骤应该是SOAP请求,就像我在m中添加的groovy脚本测试步骤一样code@Manoj您可以使用
testRunner
context
获取
project
的方式相同,但我认为您要求的是更紧凑的方式。。。在groovy测试步骤中,我认为没有。。。至少我不知道怎么做。@Manoj尽管方法的名称为cloneStep,但它确实创建了一个testStep的副本,我使用这个解决方案,因为在这个问题中,您似乎想从另一个testSuite复制一个请求,而不是创建一个新的。此外,添加一个新的测试步骤很难做到这一点,因为您需要更多的信息(端点、来自wsdl的方法…)和更多的步骤。。。