The purpose of writing registry keys and values is so that they can be used within automated tests. The reason is that, in general, automation should refrain from making changes to the operating system, and this includes the registry. This is necessary to keep our automated tests as less invasive as possible. However, it is important to know how this can be accomplished.
To write a value to a custom registry key that passes UFT data gathered by a process running in parallel to the automated test, UFT uses the RegRead
method at the appropriate time to retrieve the data. This allows, in parallel, the asynchronous usage of the testing tool and external executables.
In this recipe, we will see how to write a custom key to the registry.
From the File menu, navigate to New | Test, or use the Ctrl + N shortcut. You can use the same test as in the previous recipe.
The syntax to write the value of a registry key is as follows:
object.RegWrite sKeyPath, sKeyVal, sKeyType
Here, object
is an instance of the Wscript.Shell
class, and sKeyPath
a valid key.
An example of how to write a new custom string (REG_SZ
) type key is shown using the following code snippet:
Dim oWshShell, sKeyPath, sKeyVal, sKeyType sKeyPath = "HKEY_CURRENT_USERMyCustomKeyMyCustomDataMyValue" sKeyVal = "This is a UFT made registry key" sKeyType = "REG_SZ" Set oWshShell = CreateObject("Wscript.Shell") oWshShell.RegWrite sKeyPath, sKeyVal, sKeyType sKeyVal = oWshShell.RegRead(sKeyPath) Print sKeyVal Set oWshShell = Nothing