Ask a Question

Assigning active environment name to a variable in ReadyAPI

SOLVED
mu123
Occasional Contributor

Assigning active environment name to a variable in ReadyAPI

I have two environments set up for a project. Let's call them env1 and env2. When I set env1 as the active one, the data source used in the test should point to c:/env1/data.csv. Similarly, if env2 is the active environment, the data source should point to c:/env2/data.csv. Please let me know how to do this. 

4 REPLIES 4
KarelHusa
Super Contributor

A straightforward option is to define a project level property in each environment, e.g. InputCSVPath, and fill it with the path, e.g. c:\tmp\data.csv .

 

In your data source configuration use ${#Project#InputCSVPath} as the file location. Then, if you switch environments, your input files will change accordingly.

 

KarelHusa_0-1664451814741.png

 

Karel@apimate.eu
https://apimate.eu
mu123
Occasional Contributor

Thanks Karel for the response.

I had simplified the question a lot. The file path for the data source is 

${projDir}/Banking_Application/${env}/data/filename.csv

The environment name should appear within the path. ${projDir} is another variable that will help to run the project on multiple machines. We have different environments like test1, test2 .... Our goal is to have separate data tables for each environment in their respective folders.

KarelHusa
Super Contributor

If you need exactly the name of your environment, the following can do the trick:

 

${#Project#TestDataPath}/Banking_Application/${=project.getActiveEnvironmentName()}/data/filename.csv

 

Karel@apimate.eu
https://apimate.eu
mu123
Occasional Contributor

Thanks Karel. This is perfect

cancel
Showing results for 
Search instead for 
Did you mean: