Ask a Question

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

SOLVED
Madhusm
Occasional Contributor

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.

21 REPLIES 21
nmrao
Champion Level 3

- It is clear that you need to use for different environments.
- Was it working for you earlier? And started failing recently? If so what are the changes?
- What are the contents in the property file that was being read in the above script?
- One will only know when tried if certain thing works or not. Many use that when there was no Environment feature exists.
- Yes, command line execution is the best approach.
- It does not matter how many projects or environments if it starts working.
- The error log provided earlier says, there is a problem in line 21; the script provided above does not have 21. lines. Unless the information available is full, it is difficult for the remote people.
-Does it even log the environment name?


Regards,
Rao.
nmrao
Champion Level 3

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

 

nmrao_0-1624547233684.png

 

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.

,



Regards,
Rao.
nmrao
Champion Level 3

By the way, there is a commandline option -E available where one can directly pass the environment name. I believe, the tool itself take care of switching the environment. Please refer the documentation.
https://support.smartbear.com/readyapi/docs/functional/running/automating/cli.html


Regards,
Rao.
Madhusm
Occasional Contributor

Was it working for you earlier? And started failing recently? If so what are the changes?

 

1. This is the first time we are trying to centralize the custom properties defined for Environments. 

Our current set up is , we have environments defined  and each environments have some Custom properties defined. 

Madhusm_0-1624547599173.png

Madhusm_1-1624547678531.png

These values are used in the test step as headers in the request.

 

Now I want the custom properties as mentioned in the second picture to be set from a config file. How can we do that ? 


- What are the contents in the property file that was being read in the above script?

 

Contents of the property file 

Env1=Beatrice

Env1NodeID=12345687878788777

Env1APIKey=XrHhghghgh686868688

Env2=Anna

Env2NodeID=1234568787844545445

Env2APIKey=XrHhghghgh623232868688

.

.

When I execute the following script as a groovy script to check if the script is right following is the script and its response

Madhusm_3-1624549022912.png

It also sets the respective values in the Environment

Madhusm_4-1624549223980.png

 

 


- One will only know when tried if certain thing works or not. Many use that when there was no Environment feature exists.

 

Why I insist on Environment because our whole automation regression tests ecosystem is based on that . Now if we change then a lot of changes has to be done everywhere. Nevertheless if that is the only way then probably we have to drop the idea or create a new system. Then that also makes me think that ReadyAPI should design the usage of environment in a better way. 

 

We have a inhouse tool created for executing the regression which reads from a config file which has details like the git path , configured environments against which we want to execute the tests, tags etc. Then it picks up the latest tests from gits and executes each project based on the environments and pushes the details to a db from where we create dashboards based on the environments.


- Yes, command line execution is the best approach.
- It does not matter how many projects or environments if it starts working.
- The error log provided earlier says, there is a problem in line 21; the script provided above does not have 21. lines. Unless the information available is full, it is difficult for the remote people.

This is the script 

 

def props = new Properties();
File propFile = new File('C:/Axon_tests/Config1.properties')
props.load(propFile.newDataInputStream())
def env=props.getProperty('Env1')
log.info(env)
if (env=='Beatrice')
{
def env1 = context.testCase.testSuite.project.getEnvironmentByName("Beatrice 14.4");
context.testCase.testSuite.project.setActiveEnvironment(env1)
def NodeIDvalue=props.getProperty('Env1NodeID')
log.info(NodeIDvalue)
def APIKeyValue=props.getProperty('Env1APIKey')
log.info(APIKeyValue)
testRunner.testCase.testSuite.project.setPropertyValue("NodeID", NodeIDvalue)
testRunner.testCase.testSuite.project.setPropertyValue("APIKey", APIKeyValue)
}

 

And I have attached the error logs again. It enters the loop but does not work on the en


-Does it even log the environment name?

When I execute the above mentioned groovy script 

Without the following lines it works, the problem is getEnvironmentByName cannot find the env if executed from the setUp script as it is not able to find the proper context which I mentioned earlier.

def env1 = context.testCase.testSuite.project.getEnvironmentByName("Beatrice 14.4");
context.testCase.testSuite.project.setActiveEnvironment(env1)

 

testRunner.testCase.testSuite.project.setPropertyValue("NodeID", NodeIDvalue)
testRunner.testCase.testSuite.project.setPropertyValue("APIKey", APIKeyValue)

Madhusm
Occasional Contributor

I have environments based on BO version as well so the combinations are many , maintaining so many properties file will be cumbersome hence one file with all properties and based on the Environment it can select which properties it has to read from the file.

 

Development Env say A but on A I can have A 13.1 , A 13.2 , A 13.3 based on the BO version since the data of the tests and response changes with BO versions customers are using we have to test with different Level Versions as well. Hence we were looking for options using one file based on environment it finds the corresponding values and set it accordingly. 

 

But thanks for your solution. I will try to modify some stuffs and try to implement it to make it feassible.

nmrao
Champion Level 3

Thank you for your time and patience.
Also for the more details, I think I got better understanding now than earlier.
You are trying to adapt a custom approach, that is why not able to Environments features as is.


All the environment properties are kept in the same file, and want load only the respective properties based on the test environment. This is when the number of properties are small in number. The file will grow bigger if more and properties per environment.

If you want this(all environments properties in single file) approach, I have something in mind. Have to try.


Regards,
Rao.
Madhusm
Occasional Contributor

Hey nmrao,

 

Thank you for your patience as well.

That would be nice if you can share I will give it a try. Because this whole issue is becoming interesting as well as challenging. 

nmrao
Champion Level 3

@Madhusm 

Thanks for your interest which made me to create this project.

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

 

Please quickly go thru README and Config.groovy and give it a try running.

 



Regards,
Rao.
Madhusm
Occasional Contributor

I will try it out and get back to you. Thanks!

nmrao
Champion Level 3

Just going thru earlier replies.
If you wanted to adopt this new solution to different project(s), then have a note of 3 things
- Need 3 Default project level properties, this available.
- There is project Setup Script
- And a Teardown Script.
Copy those to the project which need this solution.


Regards,
Rao.
cancel
Showing results for 
Search instead for 
Did you mean: