Forum Discussion

TanIlak's avatar
TanIlak
Contributor
2 years ago

How to set Environment variable for script level testing

Hi team,

I am facing problem to set an environment variable for script level testing.

for example, in my code am accessing data from excel files for my script. I need to set a common path for all the scripts using environment variables to access the data in excel files, once we set that path means no need to change excel path location in each script to access those files.

 And also, I have seen some options in test complete (tools--options--tested applications) and one more in execution plan also the option is their environment variables. Can anyone help to set the environment variables used in all scripts??

 

 

  • This is SmartBear's official documentation on using envt variables [here] and passing them to pipelines [here] (if you're using pipelines). 

     

    I personally use my own "environment handler" in the form of an OnStartTest Event - see [here]. This is just a custom function that updates the envt related variables before the tests start; IE: passing the envt value (ex: DEV, QA, UAT) to the ProjectSuite or Project variables used throughout the test - like connection strings, folder paths, urls, etc. 

    function setEnvironment(envt) {
      ProjectSuite.Variables.Environment = envt;
      ProjectSuite.Variables.Site = "https://test-" + envt + "-website.com"; // using your own website url
      ProjectSuite.Variables.dboDatabaseServer = aqString.ToLower("sql-test-database-" + envt); // using your own database
      ProjectSuite.Variables.envtFolder = aqString.ToLower(ProjectSuite.Path + "\\" + envt + "EnvironmentFolder\\"); // using your own folder path
      CommonMAIN.launchChromeBrowser(ProjectSuite.Variables.Site);
      Log.Checkpoint("| Test Environmnet Set | - " + ProjectSuite.Variables.Environment);
    }

     **NOTE: if you use NameMapping and want to pass the "envt" variable to a mapped object - you'll need to use Project.Variables

  • Kitt's avatar
    Kitt
    Regular Contributor

    This is SmartBear's official documentation on using envt variables [here] and passing them to pipelines [here] (if you're using pipelines). 

     

    I personally use my own "environment handler" in the form of an OnStartTest Event - see [here]. This is just a custom function that updates the envt related variables before the tests start; IE: passing the envt value (ex: DEV, QA, UAT) to the ProjectSuite or Project variables used throughout the test - like connection strings, folder paths, urls, etc. 

    function setEnvironment(envt) {
      ProjectSuite.Variables.Environment = envt;
      ProjectSuite.Variables.Site = "https://test-" + envt + "-website.com"; // using your own website url
      ProjectSuite.Variables.dboDatabaseServer = aqString.ToLower("sql-test-database-" + envt); // using your own database
      ProjectSuite.Variables.envtFolder = aqString.ToLower(ProjectSuite.Path + "\\" + envt + "EnvironmentFolder\\"); // using your own folder path
      CommonMAIN.launchChromeBrowser(ProjectSuite.Variables.Site);
      Log.Checkpoint("| Test Environmnet Set | - " + ProjectSuite.Variables.Environment);
    }

     **NOTE: if you use NameMapping and want to pass the "envt" variable to a mapped object - you'll need to use Project.Variables

  • Ḽari's avatar
    Ḽari
    Frequent Contributor

    Even I am also having same doubt.

    Can we use using Tested Apps editor or any other ways to use define Environment variable???

     

    Please let me know if anyone knows