Forum Discussion

Ed_Bosco's avatar
Ed_Bosco
New Contributor
16 years ago

Creating properties at the Test Case level, initialized by Groovy scripts

Hi -

Have been trying to set properties at the Test Case level, initialized by Groovy Setup scripts at that Test Case level, accessible by the Test Steps beneath that Test Case.

The properties are wrote and read and logged during the Setup script execution, but don't show in the sent Soap request.

It appears that CurTime is null with the request.



CurTime is referenced in the xml below - the three time values

The Setup Script excerpt:

testRunner.testCase.setPropertyValue("CurTime", CurTime);
log.info "time is "+CurTime;
log.info "Start time is: " +  testRunner.testCase.getPropertyValue("CurTime");

---

     
         ${#TestCase#messageId}
         
         
         
         
         L243
         
         ?
     


---

The property CurTime is also listed at the Test Step Properties level, and has an initial value of ${CurTime}.


This is under SoapUI-Pro 2.0.2

8 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    If I understand you correctly, shouldn't your xml be

    ${#TestCase#CurTime}
    ${#TestCase#CurTime}
    ${#TestCase#CurTime}

    ?

    regards!

    /Ole
    eviware.com
  • Ed_Bosco's avatar
    Ed_Bosco
    New Contributor
    Thanks much.

    Yes; that's what I tried to do. I reviewed what you earlier wrote in other posts, and cleaned up the code, trying again to set those values the way you note below.

    When I try to import (Get Value) those time strings (xsd:dateTime (there's three)) to the request, the editor would revert them to ${CurTime}, an earlier entry.

    I used the Set Value option to put that string into the SOAP request.

    It appears that the "${#TestCase#CurTime}" is what is being sent, and not the data.

    I see a similar issue with {#TestCase#messageID}; If I place a known string at the Test Case property level, the test step gets it. If I try to set that property from the Groovy Setup Script, it's not seen.
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    hmm.. I've created a simple TestCase with the following setup Script:

    testRunner.testCase.setPropertyValue( "testIp", String.valueOf( Math.random() ))

    and then in my only request in the TestCase I use

    ...
    ${#TestCase#testIp}
    ...

    which works just fine.. can you attach or send me your project so I can have a look?

    regards!

    /Ole
    eviware.com
  • I see a similar situation in SoapUI 2.0.2 this afternoon -- the XML in my Test Step includes a Property Reference "${xactId}", where the 'xactId' property itself has the value "qatest_1234", and is defined at the TestCase level.

    However, the XML that actually arrives at the server has the same string as the TestStep -- i.e., " ${xactId}" --  instead of the substituted value that I was expecting: " qatest_1234".

    I am still a newbie -- have I accidentally set a flag that turns off Property Expansion?  Or perhaps I don't have my scope set correctly?  (I have tried this using "${#TestCase"xactId}", with exactly the same outcome.)
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    soapUI requires a scope-prefix currently unless you want to access global properties, using

    ${#TestCase#xactId}

    should work!

    Let me know..

    /Ole
    eviware.com
  • Thanks, Ole --

    This was an exploratory Test Suite, so I deleted it and started over, and now everything looks much better.  I defined a global Property 'xactId', and now I can dereference it as "${xactId}".  However, I get an empty string when I refer to it using "${#Global#xactId}".  Do I have the scope syntax right?  Similar exercises for "${#Project#xactId_pr}", "${#TestSuite#xactId_ts}", and "${#TestCase#xactId_tc}" all work just fine, it is just when I use the #Global# scope declaration that the string comes up empty.

    -- Sean
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Sean,

    thanks for your thorough testing :-) I've hopefully fixed the "#Global#" scope specifier, also you should know that 2.5 also introduces #System# for accessing system properties and #Env# for Environment variables..

    regards!

    /Ole
    eviware.com
  • Hi, Ole --

    Way cool!  And I'm glad I could help a little -- this is a great tool, and it just keeps getting better.

    -- Sean