Transfer Property ids (Array) to other TestCases i

2019-06-08 01:23发布

问题:

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