Forum Discussion

mmoser18's avatar
mmoser18
Frequent Contributor
9 years ago

How to access standard, i.e. non-custom, properties?

I am trying to get hold of Property values that are NOT Custom Properties

 

If I define a Customer Property "foo" I can access its value using:

def bar = context.expand('${#Project#foo}')

But how do I access those left-hand standard Properties i.e. those listed on the tabs Project Properties, TestSuite Properties, TestCase Properties, REST TestRequest Properties etc.

 

Does access to these require some other mechanism?

6 Replies

  • rupert_anderson's avatar
    rupert_anderson
    Valued Contributor

    Hi,

     

    You can access any public scope properties on SoapUI objects e.g. Projects, TestCases using Groovy scripts etc.

     

    Some examples are: 

     

    Accessing the project name from within a Groovy TestStep:

     

    testRunner.testCase.testSuite.project.name

     

    A bit more complicated example again from within a Groovy TestStep:

     

    import com.eviware.soapui.impl.wsdl.WsdlInterface

    myInterface = (WsdlInterface) testRunner.testCase.testSuite.project.getInterfaceByName("SampleServiceSoapBinding")
    myOperation = myInterface.getOperationByName("login")
    myRequest = myOperation.getRequestByName("Request 1")\

     

    These snipets were taken from http://www.soapui.org/scripting---properties/tips---tricks.html

     

    You may find the API docs helpful in working out methods/properties that you can call http://www.soapui.org/apidocs/index.html

     

    Is this what you meant?

     

    Cheers,

    Rupert

    • mmoser18's avatar
      mmoser18
      Frequent Contributor

      I must be missing something here. I have read through the docs quite intensively and I also tried the suggested code snippets, but when I enter a code-snippet like

      def name = testRunner.testCase.testSuite.project.name

      into the script assertion entry field and then execute that I get an error "can not call testCase on a null-object". So, the object "testRunner" seems undefined or null.

       

      The other usage that my question was referrring to:

      there is the option to define an assertion by using the "Contains" option and then enter a string that has to be contained in the response into the input fields.

       

      These strings can contain "placeholders" like "...${#Project#some_property}..." or "...${#TestCase#other_property}..." etc.. However, that machanism seems to work only with user definable customer properties. If I enter the project property "${#Project#Name}" here or ${#Project#Service} or ${#Project#Endpoint} or any other default property's name)  I get an error only. What name or prefix do I need to use for the Project/Test Suite/Test Case/Test Step's default properties?

      • rupert_anderson's avatar
        rupert_anderson
        Valued Contributor

        Hi,

         

        So in terms of why that first snippet deosn't work, what you were missing is that I said to run it from a Groovy script, not a script Assertion, they provide different variables to the script - see the comparison below:

        Screen Shot 2015-08-24 at 09.54.53.png

        Whereas, the Script Assertion is not run in the context of a test runner hence no testRunner variable (it gets messageExchange instead):

        Screen Shot 2015-08-24 at 09.55.48.png

         

        Ok, I think the problem here might be that the syntax for inserting the result of script type expressions is not the same as that for the property expansion syntax that is applied to properties of different scopes - consider the following example:

         

        ${=java.util.UUID.randomUUID()}

         

        (also taken from that tricks and tips page, but basically this syntax allows execution of one or more lines of code, can provide more complicated examples if necessary)

         

        Is this what you wanted?

        Hope this helps,

        Cheers,

        Rupert