Forum Discussion

Bob_K's avatar
Bob_K
Occasional Contributor
16 years ago

How can I get a property value from the Project in groovy?

I'm retrieving some information from a db, using groovy scripts in my test cases.  Instead of hard coding the userid, password, etc.  I decided to make them properties of the project.  The problem is I can't seem to figure out how to retrieve properties from the project.  I was able to get/set properties at the testcase level but can't figure out the correct syntax to retrieve the project level properties.

6 Replies

  • Bob_K's avatar
    Bob_K
    Occasional Contributor
    Thanks Robert,  I've already gone over that page and I've been able to use the sample:
    // get request property
    def request = testRunner.testCase.getTestStepByName( "Request 1" );
    def property = request.getProperty( "request" );

    to retrieve properties at the testStep and testCase level but still can't figure out how to access the properties set at the project level.  I recently tried moving the properties down to the testSuite level but still haven't been able to accees the properties.  I've tried:
    def hTestSuite = testRunner.getTestSuiteByName("My TestSuite");

    but I get the error:
    groovy.lang.MissingMethodException: No signature of method: com.eviware.soapui.impl.wsdl.panels.support.MockTestRunner.getTestSuiteByName() is applicable for argument types: (java.lang.String) values: {"My TestSuite"}
  • Bob_K's avatar
    Bob_K
    Occasional Contributor
    nevermind,  I figured it out:
    def  hTestProject = testRunner.testCase.testSuite.project.workspace.getProjectByName("MyTest");
    def pdbUserId = hTestProject.getPropertyValue("dbUserId");
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    How about:

    def propValue = context.testCase.testSuite.project.property["some prop"].value

    where  "some prop" is property name on project level.

    or :

    context.expand( '${#Project#prop name}' )

    robert
  • Bob_K's avatar
    Bob_K
    Occasional Contributor
    Thank you those make even  it easier.

    This leads to another question though,  I started using the
    dbUserId = context.expand( '${#Project#dbUserId}' );

    to pull the property value.

    How can I set a property value? I tried:
    context.setProperty( '${#TestCase#currdattim}', currentDateChar26() );

    I don't get any errors, but it also doesn't set the property value.
  • SmartBear_Suppo's avatar
    SmartBear_Suppo
    SmartBear Alumni (Retired)
    Hi,

    It is not possible to set values using property expansions, only to get them.
    To do this, you need to go "the long way" and use testRunner.testCase.properties["currdattim"].value = "new value";

    /Dain
    eviware support