Forum Discussion

kadir's avatar
kadir
Occasional Contributor
3 years ago
Solved

file for different env

I have different excel files, but all these excel files are for different environments. When I run a test case or test suite, I want to make sure data source file path changes based on the env I chose. Any help please?

 

 

  • Hey kadir 

     

    Im working on the wrong laptop at moment but I cant check - but does the file browse editable field support parameters? 

     

    I cant remember - but if it does, you could create a custom project level property indicating the environment and then point to this.

     

    so say you have 3 environments with different testdata in different folders, you could create a custom property called 'environment_path' and you could specify this before your execution by importing a properties file that contains the correct path

     

    so 3 environments = DEV, QA & CLONE

     

    create 3 properties files, 1 for each environment -

     

    in each file you would have something like 

    environment_path=C:\ReadyAPI\Project\QA

     

    once the file's created, decide which environment to execute on and then prior to execution load in the file.

     

    Then in your DataSource test step's file path editable field input the value as ${Project#environment_path}

     

    I actually do this for every single possible environment specific parameter/variable so there's minimal hard coding.  Means I can lift and shift my project to different environments without having to change any data at all.  The only thing I change is the properties file I load in, immediately before I start an execution run.

     

    ta

     

    Rich

     

     

4 Replies

  • richie's avatar
    richie
    Community Hero

    Hey kadir 

     

    Im working on the wrong laptop at moment but I cant check - but does the file browse editable field support parameters? 

     

    I cant remember - but if it does, you could create a custom project level property indicating the environment and then point to this.

     

    so say you have 3 environments with different testdata in different folders, you could create a custom property called 'environment_path' and you could specify this before your execution by importing a properties file that contains the correct path

     

    so 3 environments = DEV, QA & CLONE

     

    create 3 properties files, 1 for each environment -

     

    in each file you would have something like 

    environment_path=C:\ReadyAPI\Project\QA

     

    once the file's created, decide which environment to execute on and then prior to execution load in the file.

     

    Then in your DataSource test step's file path editable field input the value as ${Project#environment_path}

     

    I actually do this for every single possible environment specific parameter/variable so there's minimal hard coding.  Means I can lift and shift my project to different environments without having to change any data at all.  The only thing I change is the properties file I load in, immediately before I start an execution run.

     

    ta

     

    Rich

     

     

    • ChrisAdams's avatar
      ChrisAdams
      Champion Level 2

      Hi,

       

      Taking nothing away form richie 's solution but I have another approach.

       

      I haven't tried dynamically changing the file based on environment, but I do do this for selecting a given sheet within my data spreadsheet environment.

       

      Before the datasource and outside the loop, I have a Groovy script labelled 'Get Environment - Groovy Script'.

      log.info("Checking the environment");
      
      def activeEnvironment = testRunner.testCase.testSuite.project.activeEnvironment.getName();
      
      def sheetToUse = "";
      
      if (activeEnvironment.contains( "DEV")) {
      	sheetToUse = "Development";
      } else if (activeEnvironment.toUpperCase().contains("TEST") ){
      	sheetToUse = "Test";
      } else if (activeEnvironment.toUpperCase().contains("PRE") ){
      	sheetToUse = "Pre-Production";
      } else {
      	// something went wrong.
      	sheetToUse = "";
      }
      
      log.info("Currently Selected Environment :- ${activeEnvironment}.  Select sheet :- ${sheetToUse}.");
      
      return sheetToUse;

       

      My Datasource

       

      • richie's avatar
        richie
        Community Hero

        ChrisAdams 

         

         

        I kinda like your answer - gonna steal your script if you dont mind! 😉

         

        Cheers!

         

        Rich