Transfer Property ids (Array) to other TestCases in SoapUI/Groovy

邮差的信 提交于 2020-01-14 04:16:06

问题


I have an API to get list of ids, name, data etc. (TestCase name GET-APIs_OrderdByID_ASC)

I want to transfer those IDs to other following TestCases in same TestSuite or other TestSuite.

In SOAPUI, Property Transfer works within TestSteps in same TestCase. (Using OpenSource version). I need to transfer the property value among different TestCases / TestSuites.

Below is the code that I can extract ids from one testCase and also name of testCases/testSteps where I want to transfer.

import com.eviware.soapui.impl.wsdl.teststeps.*
import com.eviware.soapui.support.types.StringToStringMap 
import groovy.json.*

def project = context.testCase.testSuite.project
def TestSuite = project.getTestSuiteByName("APIs")
def TestCase =  TestSuite.getTestCaseList() 
def TestStep = TestCase.testStepList
def request =  testRunner.testCase.getTestStepByName("List_of_APIs_OrderByID_ASC")
def response = request.getPropertyValue("Response")
def JsonSlurperResponse = new JsonSlurper().parseText(response)
def Steps = TestStep.drop(3)
log.info JsonSlurperResponse.data.id   
def id = JsonSlurperResponse.data.id

Steps.each {
    it.getAt(0).setPropertyValue("apiId", id.toString())   
    log.info it.getAt(0).name       
}

If I run above code, all the array values of id [1, 2, 10, 11, 12, 13, 14, 15, 16, 17, 18] are set to each of the following testSteps

I looked some other SO questions

  • Property transfer in SOAPUI using groovy script
  • groovy-script-and-property-transfer-in-soapui

Can anyone help me out. :-)


回答1:


I have done something with datasinks as Leminou suggests.

Datasinks are a good solution for this. In test A, create a datasink step to persist the values of interest. Then in the target step, use a data source step, which links to the file generated by the datasink earlier.

The data sink can be configured to append after each test or start afresh.

If you're struggling to tease out the values for the datasink, create a groovy step that returns the single value you want, then in the datasink step, invoke the groovy.

Sounds a little convoluted, but it works.




回答2:


You can use project level properties or testSuiteLevel properties or testCase Properties.

This way you can achieve the same thing that you get from Property Transfer step but in a different way.

Write a groovy step in the source test case to setProperty(save values you want to use later)

testRunner.testCase.setPropertyValue("TCaseProp", "TestCase")
testRunner.testCase.testSuite.setPropertyValue("TSuiteProp","TestSuite") 

testRunner.testCase.testSuite.project.setPropertyValue("ProjectLevel","ProjectLevelProperty")

"TCaseProp" is the name of the property. you can give any name "TestCase" is the value you want to store. You can extract this value and use a variable for example

def val="9000"
testRunner.testCase.setPropertyValue("TCaseProp", val)

You can use that property in other case of same suite. If you want to use across different suites you can define project level property

use the below syntax in target testcase request

${#Project#ProjectLevel}
${#TestCase#TCaseProp}
${#TestSuite#TCaseProp}

<convertCurrency>${#TestSuite#TCaseProp}</ssp:SystemUsername>

System will automatically replace the property value in above request

https://www.soapui.org/scripting-properties/tips-tricks.html <-- Helpful link which can explain in detail about property transfer




回答3:


Well the following Script works. Just to change as

Steps.each { s ->
   id.each { i ->
     s.getAt(0).setPropertyValue("apiId", i.toString())            
  }
}

Here id is a ArrayList type. So We can loop through the List.

PS: We can do the same using for loop.



来源:https://stackoverflow.com/questions/46298419/transfer-property-ids-array-to-other-testcases-in-soapui-groovy

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!