Forum Discussion

DMc-Cabe's avatar
DMc-Cabe
Occasional Contributor
10 years ago

Pass values between groovy assertions ?

I'm trying to figure out if it's possible to pass values returned from one groovy assertion to another assertion on a separate test step ?

the example I have is as follows

test step1 - is a jdbc request which queries a certain table. The assertion traverses through the response for certain row values performs an assertion and creates a collection/Array with these values

test step2 - is another jdbc request which queries a separate table. The rows values i'm interested in on this request should match those which were returned in step1.

I was hoping to be able to pass the collection/array values returned from step1 into step2 so that I could do an assert containsAll between the 2 collections/Arrays.

Is something like this even possible?

testRunner.testCase.getTestStepByName wont work because it will only pass the values to the test step and not the assertion within the test step.

I've been looking at messageExchange.modelItem.testStep but can't figure out how to pass the Array value from there either

appreciate any help with this

7 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3
    1. What kind of assertions you are doin on step1 response? xpath/contains/script etc?
    2. Even if collection/array is available in step2, I beleive one could not use them in jdbc step.

    You can try storing the values(String) in test case properties, then use them in step2's jdbc.
  • DMc-Cabe's avatar
    DMc-Cabe
    Occasional Contributor
    nmrao wrote:
    1. What kind of assertions you are doin on step1 response? xpath/contains etc?
    2. Even if collection/array is available in step2, I beleive one could not use them in jdbc step.


    I'm using groovy to inspect the specific nodes in the xml

    import com.eviware.soapui.support.XmlHolder

    def holder = new XmlHolder( messageExchange.responseContentAsXml )
    def node = holder.getDomNode( "//Results[1]/ResultSet/*" )
    def i = 1 as int
    def uniqueIds = ['396775','449296','385430','648397','648396','449556','573080','648395','423574','648394','450236','573072']
    def allIds = []

    for( elementId in holder.getNodeValues( "//ELEMENTS_ID" ))
    {
    log.info "current elementId[$i] == [$elementId]"
    allIds.add(elementId)
    i++
    }
    assert allIds.containsAll(uniqueIds)
    ______

    so once I'm happy with the content of the array allIds, I want to use this to assert against in my 2nd test Step
  • DMc-Cabe's avatar
    DMc-Cabe
    Occasional Contributor
    DMc-Cabe wrote:
    nmrao wrote:
    1. What kind of assertions you are doin on step1 response? xpath/contains etc?
    2. Even if collection/array is available in step2, I beleive one could not use them in jdbc step.


    I'm using groovy to inspect the specific nodes in the xml

    import com.eviware.soapui.support.XmlHolder

    def holder = new XmlHolder( messageExchange.responseContentAsXml )
    def node = holder.getDomNode( "//Results[1]/ResultSet/*" )
    def i = 1 as int
    def uniqueIds = ['396775','449296','385430','648397','648396','449556','573080','648395','423574','648394','450236','573072']
    def allIds = []

    for( elementId in holder.getNodeValues( "//ELEMENTS_ID" ))
    {
    log.info "current elementId[$i] == [$elementId]"
    allIds.add(elementId)
    i++
    }
    assert allIds.containsAll(uniqueIds)
    ______

    so once I'm happy with the content of the array allIds, I want to use this to assert against in my 2nd test Step


    I've even tried adding a property step called 'targetIds'
    The I added the following line to my assertion above :
    messageExchange.modelItem.testStep.testCase.getTestStepByName("targetIds").setPropertyValue(allIds,allIds)

    this is returning the following error :

    No signature of method: com.eviware.soapui.impl.wsdl.teststeps.WsdlPropertiesTestStep.setPropertyValue() is applicable for argument types: (java.util.ArrayList, java.util.ArrayList) values: [[666, 2109, 2108, 21, 445, 2207, 2218], ...]
    Possible solutions: setPropertyValue(java.lang.String, java.lang.String), getPropertyValue(java.lang.String)
  • nmrao's avatar
    nmrao
    Champion Level 3
    As mentioned earlier, property value can only be String type.
    In this case not sure if possible, need to store each value in a separate property in order to use.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    You can pass it as String, by converting it to String and when you retrieve it in the next step convert them back to desired Datatype.

    Thanks,
    Jeshtha
  • We had the same problem statement. Here is the answer to the problem (curtsy user daggett). 

     

    https://stackoverflow.com/questions/44421624/how-to-pass-a-two-dimensional-list-array-between-groovy-scripts-in-soap-ui 

     

    Below is the summary of answer from him.

    First groovy script: 

    def array = ['Kyiv', 'Boryspil', 'Kharkiv', "L'Viv", "Odesa"]context.setProperty('cities', array)log.info( 'script1: '+array )

     Second groovy script: 

    def array = context.getProperty('cities')log.info( 'script2: '+array )
    assert array.size()>0

     

    [daggert] : Note

    If you run just one step, then there will be absolutely independent context.

    But if you run the whole testcase then there will be context shared for the whole testcase.

    You can use Run from here context menu in your test case window to run from exact step. 

     

    P.S: Above note is the key that we were missing.

    Open your script log in test case to verify that you indeed get the right values as mentioned in above two groovy scripts.

    • groovyguy's avatar
      groovyguy
      Champion Level 1

      While posting solutions and helping is great, usually reviving a thread that's this old isn't a good idea.