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 2

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.

 

Madhusm_0-1624438243943.png

 

nmrao
Champion Level 2

Have you tried the approach link given in the previous reply?


Regards,
Rao.
nmrao
Champion Level 2

What does the log say? Error in which line ?


Regards,
Rao.
Madhusm
Occasional Contributor

The error is in these lines it is not able to get the Environment based on context when executed as setscript at test suite level , I also tried with 

def env1 = context.testSuite.project.getEnvironmentByName("Test 14.4"); 

It still showed error on the same line number.

 

I have attached the error logs , the error is in line 8 

 

def props = new Properties();
File propFile = new File('C:/Axon_tests/config.properties')
props.load(propFile.newDataInputStream())
def env=props.getProperty('Env')
log.info(env)
if (env=='Test')
{
def env1 = context.testCase.testSuite.project.getEnvironmentByName("Test 14.4");
context.testCase.testSuite.project.setActiveEnvironment(env1)
log.info(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)
}*/

nmrao
Champion Level 2

Where is script located in the project?
Why do you want to change the environment in the middle of the execution?


Regards,
Rao.
Madhusm
Occasional Contributor

I have added this as setup script as I understand setup script is executed at the beginning , the problem I'm trying to solve here is we have env defined but the custom properties values of the env we are trying to set up using a generic file. So in future when there is a change in one property I do not have to visit each project and manually change the values. At the time of execution , first it could do the setup and execute accordingly.

 

The problem I'm facing now is if I use the getEnvironmentbyName from the setupscript it is not able to find the context and throws an exception.

 

Madhusm_0-1624515650160.png

 

 

 

nmrao
Champion Level 2

@Madhusm 

Gave the answer with a link in my first reply which does the same . And also asked the followup question and it is not answered yet.

The link given does the same thing.

You add the all the properties in a file. And import in project and access them where all you need. No programming/scripting required. Just access ${#Project#PROPERTY_NAME}

The tool does many cool things in simple way.

And the above does not use Environment feature also.

 

You can have multiple property files by environment wise.

Try it and see.

 



Regards,
Rao.
Madhusm
Occasional Contributor

Hi nmrao,

 

My requirement is to use it with environment variable as we have dev, test , Staging and dev environment which executes with different BO release versions  combinations. And we have close to 600 ReadyAPI projects which executes every night. And by using the environment defined and tags defined we also control the execution of a test set in different environments. 

 

This environment feature helps in maintaining the tests in better way and the execution of tests using the command line version of ReadyAPI. The way you suggested will not work for us. Hence I insisted on using a script which will do the needful. As currently ReadyAPI does not provide an option to do that.

 

Regards

Madhusmita

cancel
Showing results for 
Search instead for 
Did you mean: