Forum Discussion

Desmond_Cassidy's avatar
Desmond_Cassidy
Contributor
16 years ago

Creating Propertiues at the Project level...

Hi,
  Apologies if this is covered in some other place...or more to the point - where in the Groovy Guid eare the basics of Property creation specified.

I would like to dynamically create several named properties at either
1. The Project Level
2. The Suite Level
(THere doesn;t seem to be the possiblility of creating Global Properties - not that I can see anyway).

So, in One Groovy Script I would like something like...

import java.text.*;

SimpleDateFormat df1 = new SimpleDateFormat("yyyy-MM-dd");
      SimpleDateFormat df2 = new SimpleDateFormat("HH:mm:ss.S");
     
      String TodayPlus14 = df1.format( new Date() +14;) + "T" + df2.format( new Date() +14; );
String TodayPlus21 = df1.format( new Date() +21;) + "T" + df2.format( new Date() +21; );

...and now create (and I guess a check to see if the property is already defined - as in a Re-Reun!) and load properties like TodayPlus14, TodayPlus21 (OK..the ame name but doesn;t have to be !). ...into either the Project , Test Suite or indeed Global level...

Not being a java programmer...all this seems a little obtuse to me...

Any help appreciated...

Cheers,

Dezzz.

7 Replies

  • omatzura's avatar
    omatzura
    Super Contributor
    Hi Dezzz,

    sure, to set a property all you need to do is call the corresponding setPropertyValue, ie

    testCase.setPropertyValue( name, value )

    or

    project.setPropertyValue( name, value )

    if the property doesn't exist, it will be created first. Depending on from where you are doing this, access to the object model differs. For example from inside Groovy Script TestStep, you would do

    testRunner.testCase.testSuite.project

    to get the project. Let me know your specific context and I'll help you forward!

    Also, you can set global properties with

    com.eviware.soapui.SoapUI.globalProperties.setPropertyValue( name, value )

    (since 2.5 version)

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • OK...Many thabks OLe...much appreciated...Looks great...

    SO...all the way up the tree is as follows...

    testRunner.testCase.testSuite.project.setPropertyValue("FirstName", "Desmond" )
    testRunner.testCase.testSuite.setPropertyValue( "LastName", "Cassidy")
    testRunner.testCase.setPropertyValue( "MiddleName", "Peter")

    Now to set it in a DIfferent Project or TestSUite or TestCase than the 'Tree' i am in...

    Cheers,

    Dezzz.
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi,

    you can always navigate back "down" the tree with either xXCount/getXXAt/getXXByName methods, for example testSuite.testCaseCount / testSuite.getTestCaseAt( ix ), or XXs[name], for example project.testSuites["TestSuite 1"]

    You can get the workspace with project.workspace and then another project with getProjectByName.. A complete example:

    testCase.testSuite.project.workspace.getProjectByName( "Project 3" ).testSuites["TestSuite 3"].getTestCaseAt( 2 )

    One thing to know is that there is no workspace when running tests using the command-line runners, so project.workspace will return null.

    Hope this helps!

    regards,

    /Ole
    eviware.com
  • Hi Ole,

    using the properties i create a project property test.IMDBurl filled with a groovy script:

    String url = 'http://' + ipAddress + ':8088'

    testRunner.testCase.testSuite.project.setPropertyValue("test.IMDBurl", url )

    now i want to use this test.IMDBurl property as the endpoint. but whenever i call an endpoint with this property i get a empty response.

    in the endpoint i tried this settings:
    $(project.getPropertyValue("test.IMDBurl"))
    $(test.IMDBurl)

    and a few others but none worked.

    what would be the entry as the endpoint to make this work?

    thanks
    Chris
  • omatzura's avatar
    omatzura
    Super Contributor
    Hi!

    please try

    ${#Project#test.IMDBurl}

    (The "#Project#' part tells soapUI in which scope to look for the property..)

    does that help?

    regards,

    /Ole
    eviware.com