TanIlak
2 years agoContributor
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 t...
- 2 years ago
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