Forum Discussion

tinoboehme's avatar
tinoboehme
Occasional Contributor
13 years ago

[res] shared Object / Variable (not Property) within a test

Hello,

is there a possibility to share an Object or an Variable within a testRun?
e.g. I have two groovy testSteps and I'm creating in the first step an Object of an own class:

def myObject = new soapui.utils.myUtils( context, log)
assert "1st TestStep" == myObject.context.testCase.getName()

Now I need to access the same (!) Object within the second testStep:

????
assert "1st TestStep" == myObject.context.testCase.getName()

In this case I get following Error message and the TestStep is failed:
[tt:35su6o8z]ERROR:An error occured [No such property: myObject for class: Script3], see error log for details[/tt:35su6o8z]

I don't want to create a new object:

def myObject = new soapui.utils.myUtils( context, log)
assert "2ndTestStep" == myObject.context.testCase.getName()


If I try to save this Object at a Property I get only a string containing the reference:
[tt:35su6o8z]soapui.utils.myUtils@2fb5a9d9[/tt:35su6o8z]
Is it possible to use this string to fetch the initial created Object?

Regards Tino

4 Replies

  • Hi Tino,

    Thank you for your detailed inquiry.

    SoapUI properties only contain strings, so when saving an object to a property what is actually stored is the string representation of the object. Thus, getting your old object is unfortunately not possible.

    If you wish, we can create a feature request for this to be implemented.


    Regards,

    Arian
    SmartBear Sweden
  • tinoboehme's avatar
    tinoboehme
    Occasional Contributor
    To save the string representation of the object inside a property is only one idea to get the same Object state back.
    But as I found in a similar thread this is not possible

    Another Idea is to save this object reference at a public variable within the testRunner object.
    Is there any similar method to achieve this?

    pseudo code for 1st TestStep:

    def myObject = new soapui.utils.myUtils( context, log)
    testRunner.setObjectReference("myObject", myObject)
    assert "1st TestStep" == myObject.context.testCase.getName()


    pseudo code for 2nd TestStep:

    myObject = testRunner.getObjectReference("myObject")
    assert "1st TestStep" == myObject.context.testCase.getName()


    If there is no similar method, it would be nice if you can create a feature request for the implementation of this Methods.

    Regards Tino
  • Hi Tino,

    If you want to share objects between TestSteps in the same case, you can simply save them in the test case's context (it has basic Map<Key, Value> functionality), like this:


    def myObject = new SomeSortOfObject()
    context.put("AStringKey", myObject)

    and then access them in a different test step using


    context.get("AStringKey")


    I hope this helps you solve your problem!

    Regards,

    Arian
    SmartBear Sweden