- 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
.
- Flask Blueprints
- 少年輕松趣編程:用Scratch創(chuàng)作自己的小游戲
- Java虛擬機字節(jié)碼:從入門到實戰(zhàn)
- Python 3破冰人工智能:從入門到實戰(zhàn)
- Mastering macOS Programming
- Lighttpd源碼分析
- UNIX Linux程序設(shè)計教程
- HTML+CSS+JavaScript網(wǎng)頁設(shè)計從入門到精通 (清華社"視頻大講堂"大系·網(wǎng)絡(luò)開發(fā)視頻大講堂)
- Learning Docker Networking
- Go語言入門經(jīng)典
- Hack與HHVM權(quán)威指南
- Joomla!Search Engine Optimization
- 零基礎(chǔ)學(xué)Java(第5版)
- 計算機應(yīng)用基礎(chǔ)(Windows 7+Office 2010)
- 情境微課開發(fā)(第2版)