2016-02-23 83 views
2

我正在尋找添加SOAP請求測試案例中的測試步驟來自不同的TestSuite和測試用例,我已經編寫了部分代碼以添加Groovy腳本用於相同的需求,但無法添加SOAP請求測試步驟。任何幫助?我們如何添加SOAP請求使用groovy腳本測試案例中的測試步驟

下面是我的代碼:

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\')' 

回答

2

你可以得到另一個測試套件,測試用例,並一步步測試,通過它的名字通過項目如下:

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添加到y我們的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") 

編輯基於COMMENT

如果不是一步步測試,你要創建一個新的彼此SOAP的副本,你可以把它用做遵循代碼。考慮到要創建一個SOAP類型的testStep,比起創建一個groovy的時候需要更多的信息,因爲需要wsdl操作信息(在這個例子中,我們採用第一個信息,但如果你有多個信息處理你拿什麼)。

IMO第一種方法比較簡單,你可以複製另一步步測試,並改變你想要的屬性...無論如何,如果你想在這裏做這種方式你:

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>' 

希望它能幫助,

+0

我還有一個問題@albcliff是否有任何其他方式獲取項目引用。我的意思,而不是def project = context.testCase.testSuite.project – Manoj

+0

克隆不是我正在尋找的,我需要從另一個測試套件中添加一個新的測試步驟,並且該測試步驟應該是SOAP請求就像我已經在m代碼中添加groovy腳本測試步驟 – Manoj

+0

@Manoj你可以像'context'一樣使用'testRunner'來獲得'project',但我認爲你需要一個更緊湊的方式... in一個時髦的測試步驟我認爲沒有......至少我不知道如何。 – albciff

相關問題