1

I want to do the following in SOAPUI using Groovy:

In a TestCase1 select values (Lastname, firstname) from database, and create a Map with dynamic values: def Map = [Login :"$Login", Nom: "$Nom"]

I need my map to be transferred to another TestCase, for this I'm 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 using:

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

Hopefully you can help me solving this problem.

Thanks advance

albciff
  • 18,112
  • 4
  • 64
  • 89
scoopy
  • 43
  • 5
  • I am not sure what your use case is. General practise that test case should be independent. Can you please tell what your use case is ? Also, do you just want only the two values or more? By the way, a map can't be set as value into test case property. – Rao Jun 21 '16 at 12:10
  • It is only possible if you can run `first test case` using groovy script of `second test case` using the context, they way you mentioned. But not thru the properties. – Rao Jun 21 '16 at 12:12
  • Instead of map, you can set each property as String value. – Rao Jun 21 '16 at 12:22
  • In my TestCase2 I need get Map from TestCase1 which I have to convert to bean object. – scoopy Jun 21 '16 at 12:24
  • I know it's possible to send each property, but it'is not solution for me, I need to set Map and i wich to change of objects with the as keyword in Groovy , but in another groovy testCase I can get it using context – scoopy Jun 21 '16 at 12:41
  • I want more than two values and not only of string type – scoopy Jun 21 '16 at 12:52
  • Wee, I already mentioned in 2nd comment. Do you want that how to implement? – Rao Jun 21 '16 at 13:25
  • The first thing you need to keep in mind, is that in SoapUI _everything_ is a String! If you read the error carefully, you will notice the signature for the method is `setPropertyValue(Strig propertyName, String value)`. – SiKing Jun 21 '16 at 15:40

1 Answers1

1

As @SiKing correctly explain in the comments, setPropertyValue method expects and String for the property name and for the property value.

Note that as @Rao suggest in general testCase execution should be independent, however despiste this technically it's possible to do what you ask for.

So a possible solution for your case is in the first testCase to serialize the Map to String in order that it's possible to save using setPropertyValue(Strig propertyName, String value) method, and then in the second testCase deserialitze it, something like the follow code must work:

TestCase 1

Serialize the map using inspect() method and save it as a property:

def map = ['foo':'foo','bar':'bar', 'baz':'baz']
testRunner.testCase.setPropertyValue('map',map.inspect())

TestCase2

Deserialitze the String property using Eval.me(String exp)::

// get the first testCase
def testCase1 = testRunner.testCase.testSuite.testCases["TestCase1"] 
// get the property
def mapAsStr = testCase1.getPropertyValue('map')
// deserialize the string as map
def map = Eval.me(mapAsStr)
assert map.foo == 'foo'
assert map.bar == 'bar'
assert map.baz == 'baz'
albciff
  • 18,112
  • 4
  • 64
  • 89