- Advanced UFT 12 for Test Engineers Cookbook
- Meir Bar Tal Jonathon Lee Wright
- 329字
- 2021-08-05 17:09:13
Using a configuration file to manage test environments
As shown in the previous recipe, it is possible to read variable values from an .ini
file. We will show how to define several environments within such a file and load the input data for the current environment during runtime.
Getting ready
Follow the same steps stated in the Getting ready section of the Reading values from an INI file recipe.
How to do it...
Create a new file with the name QA-env-settings.ini
. Enter the following entries to create three sets of parameters corresponding to three test environments QA1
, QA2
, and QA3
:
[QA1] InputDataSrc= "RegressionData1.xls" Username = "user1" URL = "http://www.url1.com" Description = "Data for QA1 environment" [QA2] InputDataSrc= "RegressionData2.xls" Username = "user2" URL = "http://www.url2.com" Description = "Data for QA2 environment" [QA3] InputDataSrc = "RegressionData3.xls" Username = "user3" URL = "http://www.url3.com" Description = "Data for QA3 environment"
In our test, we will load the input data based on the value of the Environment variable QA_ENV
, which will take one of the following environments: QA1
, QA2
, or QA3
. Before running the test, ensure that the variable exists, and provide the value for the required testing environment (see the Storing data in the Environment object recipe). Therefore, our code in Action1
will look like the following code snippet:
Dim sDataSourcePath, sURL, sUsername oExtern.GetPrivateProfileString(Environment("QA_ENV"), _ "InputDataSrc", "", sDataSourcePath, 255, _ "QA_env_settings.ini") oExtern.GetPrivateProfileString(Environment("QA_ENV"), _ "InputDataSrc", "", sURL, 255, "QA_env_settings.ini") oExtern.GetPrivateProfileString(Environment("QA_ENV"), _ "InputDataSrc", "", sUsername, 255, "QA_env_settings.ini") DataTable.Import(sDataSourcePath)
How it works...
We retrieve the value of the QA_ENV
Environment variable, and accordingly load the values of the variables in the corresponding section in the .ini
file. The value of the InputDataSrc
key within the corresponding section is then retrieved (note that the parameter is passed by reference and filled by the target method) and is used to import the Excel file (as you can see in the Importing an Excel file to a test recipe) that contains the input data for the given testing environment.
- 深入淺出Prometheus:原理、應(yīng)用、源碼與拓展詳解
- Integrating Facebook iOS SDK with Your Application
- Learning YARN
- Domain-Driven Design in PHP
- 3ds Max印象 電視欄目包裝動(dòng)畫與特效制作
- App Inventor 2 Essentials
- Mastering Embedded Linux Programming
- 實(shí)驗(yàn)編程:PsychoPy從入門到精通
- Android初級(jí)應(yīng)用開發(fā)
- Processing開發(fā)實(shí)戰(zhàn)
- 系統(tǒng)分析師UML用例實(shí)戰(zhàn)
- SQL Server 2014數(shù)據(jù)庫設(shè)計(jì)與開發(fā)教程(微課版)
- 情境微課開發(fā)(第2版)
- C#開發(fā)之道
- Neo4j High Performance