Forum Discussion

Madhusm's avatar
Occasional Contributor
3 years ago

Centralizing the custom properties defined for Environments. Want to read values from a config file.

We have projects created which has to be executed across N environments. Currently it is quite cumbersome to manually create environments and maintain it.
For example I have an environment defined XYZ and a custom property defined .Now if there is a change in the property value have to manually edit all the projects for the property to get updated.

How can I use one centralized file with all properties defined and based on the environment it can make the changes to that environment. What are the options I have to implement this?

Sample Config file 



I have projects with environments defined as in the snapshot attached, now I want to set these properties from a generic config property file which has these properties defined with different values based on the environment. So when I execute the test I want that properties are extracted from the generic config file at the time of execution based on the environment chosen.

  • nmrao's avatar
    3 years ago

    Just to demonstrate, created a simple project, called testProperties

    - This project contains a single test suite and test case which contains a groovy script test step.

    - The groovy script test step access the project properties. Of course, any test step in the project can access these properties which every knows.

    - Created two property files. These property files are being passed as arguments to testrunner script command line

    -- => contains environment details of QA

    -- => contains environment details of Staging

    - This is completely handled as out-of-the-box functionality of the tool, so no burden for the user at all.

    - The argument needs to pass is<projectName>=<property file path>

    - The projectName in the above is what you see in when the project is opened in the tool. or you can find in the project properties Name field. In my case, my project is named as "testProperties"

    - Here is the excerpt from the command line execution of the project and they show the correct values loaded from the property file. Notice the log statements.

    - You can see the command

    ./ testProperties-soapui-project.xml



    Attaching the sample project (created in free version for the benefit of SoapUI  tool users as well), so one can try themselves by downloading the artifacts.




    One can added as many properties required for the each environment in separate file and just pass the respective file when needed.


    Of course, one can use Environment feature if there is need and when they have pro tool. I am sure, it must be possible to switch the environment name from the command-line, i am not familiar about that. One should be able find it in the documentation. I am wondering why one need to write the script like what you have.


21 Replies

    • Madhusm's avatar
      Occasional Contributor

      What I did was I wrote a groovy script which would change the  custom properties. This script works well when used as Groovy step.

      However, I want this groovy script to be executed as the Load script or set up script. On trying to execute the following script as setupscript   I get error:


      def props = new Properties();
      File propFile = new File('C:/Axon_tests/')
      def env=props.getProperty('Env')

      if (env=='Test')
      def env1 = context.testCase.testSuite.project.getEnvironmentByName("Test 14.4");
      def NodeIDvalue=props.getProperty('NodeID')
      def APIKeyValue=props.getProperty('ÁPIKey')
      testRunner.testCase.testSuite.project.setPropertyValue("NodeID", NodeIDvalue)
      testRunner.testCase.testSuite.project.setPropertyValue("APIKey", APIKeyValue)


      I get error if I try to execute it as setup script. Can anybody please help me with this how to resolve this.



      • nmrao's avatar
        Champion Level 3
        Have you tried the approach link given in the previous reply?