Forum Discussion
Thanks again for your response to help.
Well I first set the below statement to WsdlTestCase.metaClass.myList3 = [1,2,3,4,5] and check the values in log.info.
Later when I manually change the value to WsdlTestCase.metaClass.myList3 = [11,2,3,4,5,"adfad"] and run it again, I get the same old values.
Note: Its repeatable. If you try couple of times, some times you will see the value getting updated but sometimes not. May be there is something that creates this behaviour in script but I am as a bit puzzled to understand this? And by the way, I didnt even used two scripts, the log.info was used in the same script. So that makes it even more puzzling.
First of all do not aware that you need to update that list repeatedly.
With meta programming, user can set the object value only once, it seems, based on your comments and below test. I did not have to update earlier, so do not aware of it.
Here is the test code which does set the value and do not update it again :
class Test {
}
Test.metaClass.myList = ['adfd',1,2,3]
def t = new Test()
println t.myList
Test.metaClass.myList = ['adfd',1,2,3,'new value']
//Outputs same old value.['adfd',1,2,3]
println t.myList
If you use case demands updating the value, then you could do as below:
class Test {
}
Test.metaClass.myObject = new Expando(list: ['adfd',1,2,3])
println new Test().myObject.list
Test.metaClass.myObject = new Expando(list:['adfd',1,2,3,'new value'])
println new Test().myObject.list
- PramodYadav9 years agoContributor
Hi nmrao : Thanks for your reply. I am learning new stuff every time you reply :). In the solution you mentioned, how can I use updated values in a second script? So a use case as mentioned below.
class Test { } Want to keep updating this list/array in script 1:
Test.metaClass.myObject = new Expando(list: ['adfd',1,2,3])
// Update in second run with say: Test.metaClass.myObject = new Expando(list:['adfd',1,2,3,'new value']) println new Test().myObject.list
Want to call this in Script 2: println new Test().myObject.listThanks again for your efforts and help!
- nmrao9 years agoCommunity Hero
If you see the stackoverflow thread, it would be clear.
https://stackoverflow.com/questions/44421624/how-to-pass-a-two-dimensional-list-array-between-groovy-scripts-in-soap-ui/44469058#44469058
Ok, let me clarify:Gave a class Test as an example, may you were thing that this is not available in other script, hope this your confusion, right?
In your case, we are using WsdlTestCase class which is available in every groovy script.
Script 1
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase WsdlTestCase.metaClass.myObject = new Expando(myList: [1,2,3,4,5]) log.info "list initialized: ${context.testCase.myObject.myList}"Script 2
import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase WsdlTestCase.metaClass.myObject = new Expando(myList: [1,2,3,4,5, 'add new item']) log.info "list initialized: ${context.testCase.myObject.myList}" - nmrao9 years agoCommunity HeroI gave that example because you mentioned that it is even having a problem even if it is updated with in the same groovy script.
- nmrao9 years agoCommunity Hero
- PramodYadav9 years agoContributor
Hi nmrao , Sorry I couldnt get back to you on this one. My bad.
Actually I tried the script but the scenario is a little different.
I want to make changes in " script1" - multiple times and than read updated changes in "script2".
I tried the new solution that you shared but the changes to original list were made in script2.
Is there a way, we can pass lists for above problem statement? Really appreciate you spending your time and efforts to help out and going out of the way to follow up as well. Thanks!
- nmrao9 years agoCommunity HeroPramodYadav,
1. If you need to update the list the same script, you can assign the latest only right?
2. Message 20 gives the same example updating the value.
If that still does not resolve the issue, would you mind creating a simple project with test case reproducing what you are mentioning? You can create project with just groovy scripts (do not have to use your wsdl etc). - PramodYadav9 years agoContributor
Well message 20, updates and reads the list in the same script.
In our problem statement, we have a data driven groovy script that reads input xmls from a folder. For each xml, we take the payload information in an array/list (script1) which we want to use in script2 for validations with DB2. Since the input xmls will keep changing in this data driven setup, next time when we run script1, the list value is changed, which we now wants to read in script2.
The example in message 2, both changes and reads the values in same script. What we want is,Test.metaClass.myObject = new Expando(list: ['adfd',1,2,3]) in script 1 and log.info new Test().myObject.list in script 2. Later for testing purposes, when i change the value in script 1 of list, I wanted to be able to read it in script 2 with asme log.info new Test().myObject.list.
class Test {
}
Test.metaClass.myObject = new Expando(list: ['adfd',1,2,3])
log.info new Test().myObject.list
Test.metaClass.myObject = new Expando(list:['adfd',1,2,3,'new value'])log.info new Test().myObject.list
- nmrao9 years agoCommunity Hero1. can you please confirm if the code mentioned working?
2. from the above message, did not get the outstanding issue.
3. attaching a demo project to reproduce the issue would be helpful if possible.