Forum Discussion

swety's avatar
swety
New Contributor
8 years ago

How pass groovy HashMap via testcase ?

 

I want to do the following in soapUI using Groovy:

TestCase1:
Select values (Lastname, firstname) from database
Create hashMap with dynamique value

def Map = [Login :"$Login", Nom: "$Nom"]

I need my map to be transferred to another TestCase, for this
i trying to put my Map into properties

> testRunner.testCase.setPropertyValue( "Map", Map)

But i have error:

> groovy.lang.MissingMethodException: No signature of method:
> com.eviware.soapui.impl.wsdl.WsdlTestCasePro.setPropertyValue() is
> applicable for argument types: (java.lang.String,
> java.util.LinkedHashMap) values: [OuvInfoPersoMap,
> [Login:dupond0001, Nom:Dupond]] Possible solutions:
> setPropertyValue(java.lang.String, java.lang.String),
> getPropertyValue(java.lang.String) error at line: 123

I found some posts on internet that suggests to use metaClass groovy property

> context.testCase.metaClass.map = Map
log.info context.testCase.map

But I don't think it enough in my case


I would like to be able to pass a map to Testcase2

Testcase2:

> createMap =
> testRunner.testCase.testSuite.project.testSuites.testCases["TestCase1"]
> createMap.map

Hopefully you can help me solving this problem.

Thanks advance

 

4 Replies

  • You can save the hashmap as TestSuite property and then re convert string to hashmap and refer it in another case. Since TestSuite property can be shared between testCases if they are in the same suite.

     

    testRunner.testCase.testSuite.setPropertyValue( "Map", Map.toString())

     

     

     

    • swety's avatar
      swety
      New Contributor

      Thanks for your answers, I want to use context to transfert my map between two TestCase

      I create and write to the map in TestCase1

       

      // create map inside testcase1
      def Map = [Login :"Login", Nom: "Nom"]
      
      //set the map in the context
      context.setProperty("Map", "Map)

        But in testcase2 when I try to get the  map using context I get nothing : the variable is not passed into it

       

      testRunner.testCase.testSuite.project.testSuites.testCases['testcase1'].context.Map

       

       Thanks advance for your help

       

      • zsousa's avatar
        zsousa
        Contributor

        did you ever figure this out? I am running into same issue