passing values from multiple scripts
- 9 years ago
ok I figured it out, how to pass a MAP to another groovy script and modify it.
This is how I did it.
1. create your map
2. serialize your map
3. save you map as a test case property
4. in the script your calling, all you have to do is de-serialize the property and use it like a map.
See code below:
import groovy.json.JsonBuilder
def scripts
def sumNum1
testRunner.testCase.removeProperty("map")
def map2 = [:]
def n
for(i=0;i<testRunner.testCase.getPropertyNames().size();i++){
n = testRunner.testCase.getPropertyAt(i).getValue()
def y = testRunner.testCase.getPropertyAt(i).getName()
map2.put(y,n)
}
scripts = testRunner.testCase.testSuite.project.testSuites["sand_box"];
scripts.testCases["TestCase 1"].testSteps["Groovy1"].run(testRunner, context);builder = new JsonBuilder()
builder(map2)testRunner.testCase.setPropertyValue("map",builder.toString())
sumNum1 = context.myClass1.myMethod(context.testCase)class script:
import groovy.json.JsonSlurper
context.setProperty("myClass1", new MyClass());class MyClass extends GroovyTestCase{
def slurper
def V3
def m
def myMethod(x){
slurper = new JsonSlurper()
V3 = x.getPropertyValue("map")m = slurper.parseText(V3)
return m["C1"]
}
}