Forum Discussion

mu123's avatar
mu123
Occasional Contributor
3 years ago

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. 

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

     

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

     

  • KarelHusa's avatar
    KarelHusa
    Champion Level 1

    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.

     

     

  • mu123's avatar
    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's avatar
      KarelHusa
      Champion Level 1

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

       

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