Forum Discussion

Madhusm's avatar
Madhusm
Occasional Contributor
4 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 

Env1=Beatrice
Env1.NodeID=123456789
Env1.APIKey=Abnjjjkj89090909
Env2=Alex
Env2.NodeID=4665656565656
Env2.APIKey=Abjjkjkj87887878787
EnvN=XYZ
EnvN.NodeID=467878799956565656
EnvN.APIKey=MNKKjjkjkj87887878787

 

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
    nmrao
    4 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

    -- qa.properties => contains environment details of QA

    -- staging.properties => 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 -Dsoapui.properties.<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

    ./testrunner.sh testProperties-soapui-project.xml -Dsoapui.properties.testProperties=qa.properties

     

     

    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.

     

    https://github.com/nmrao/sample-soapui-projects/tree/master/environmentsExample

     

     

    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.

    ,

    • Madhusm's avatar
      Madhusm
      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/config.properties')
      props.load(propFile.newDataInputStream())
      def env=props.getProperty('Env')

      if (env=='Test')
      {
      def env1 = context.testCase.testSuite.project.getEnvironmentByName("Test 14.4");
      context.testCase.testSuite.project.setActiveEnvironment(env1)
      def NodeIDvalue=props.getProperty('NodeID')
      def APIKeyValue=props.getProperty('ƁPIKey')
      log.info(APIKeyValue)
      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
        nmrao
        Champion Level 3
        Have you tried the approach link given in the previous reply?