- Advanced UFT 12 for Test Engineers Cookbook
- Meir Bar Tal Jonathon Lee Wright
- 389字
- 2021-08-05 17:09:13
Reading values from an INI file
Files with the extension .ini
are the legacy of the old Windows versions (16 bit). In the past, they were extensively used—and still are to some extent—ubiquitously to store the settings for applications. Nowadays, it is common practice to store settings in the registry. Though textual, such files have a very well-defined structure; there are sections and key-value pairs. A section starts with a label enclosed in square brackets: [section-name]
and a key-value is implemented as <variable name>=<value>
. Such a structure could be useful, for instance, if we wanted to keep the settings organized by environments or by user profiles within an.ini
file.
Note
In this recipe, you will also see an example of how to use the Extern
reserved object to define references to methods in external DLLs, such as those of the Win32API. These methods can then be loaded and executed during runtime. A more elaborate description is available in the Drawing a rectangle on the screen with Win32 API methods (Extern) recipe of Chapter 8, Utility and Reserved Objects.
Getting ready
To complete this recipe, we need to use the global Extern
object, which with proper use provides the UFT with access to the methods of an external Dynamic Link Library (DLL). We will define a variable and assign it a reference to the global Extern
object (this is done to avoid persistence, as Extern
is a reserved object not released from memory until UFT closes):
Dim oExtern set oExtern = Extern
Then, we will declare the method or methods we wish to call from the relevant Win32API. In this case, the method is GetPrivateProfileString
, which retrieves the value of a given key within a specific section:
oExtern.Declare micInteger,"GetPrivateProfileString", "kernel32.dll","GetPrivateProfileStringA", _ micString, micString, micString, micString+micByRef, micInteger, micString
How to do it...
After defining the connection to the DLL with its returned value and arguments, we can retrieve the value of any key within a given section. In the following example, the ConfigFileVersion
key specified in the file wrls.ini
is located in the UFT/bin
folder. In the end, the Extern
object reference is destroyed at the end of the run:
call oExtern.GetPrivateProfileString("ProgramInformation", "ConfigFileVersion", "", RetVal, 255, "C:\Program Files\HP\Unified Functional Testing\bin\wrls_ins.ini") print RetVal set oExtern = nothing
The output to the console in this case was the string 1.05
.
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- DevOps for Networking
- Python 深度學(xué)習(xí)
- Cassandra Design Patterns(Second Edition)
- Learning Informatica PowerCenter 10.x(Second Edition)
- Mastering OpenCV 4
- UI智能化與前端智能化:工程技術(shù)、實(shí)現(xiàn)方法與編程思想
- 秒懂設(shè)計(jì)模式
- Easy Web Development with WaveMaker
- Mastering RStudio:Develop,Communicate,and Collaborate with R
- Cocos2d-x學(xué)習(xí)筆記:完全掌握Lua API與游戲項(xiàng)目開發(fā) (未來書庫)
- SQL Server從入門到精通(第3版)
- Mastering openFrameworks:Creative Coding Demystified
- Java語言程序設(shè)計(jì)教程
- Mastering C++ Multithreading