A mode of parameterization, but using usage of Env variables is choice made during the framework definition.
Alternatively it is global variable defined either within or outside the scope of QTP. Read on how the above two differ.
Environment variables can be of two types in general:
System Defined (Built - In)
User Defined
The first class is usually read only variables, where as the second one's are User specific.
However when it comes to QTP, there can be env variables within the scope of QTP, used for parameterization, but system environment variables
which are used to control the software’s and operations of the local machine can also be accessed through this mode.
Environment tab is under File/Test Settings menu in QTP.
Users can create their own variables which would be local to the scope of the test being defined in.
The same variables can be accessed from the script as below:
Environment.value("varName") 'to create variables at run time.
Environment("varName") 'if variable is already defined
Built In variables can be accessed in the same way as above:
Environment("TestName")
Alternative users can create an external xml file and load the values into the system at runtime.
However the variables would be read only and cannot be edited during script run.
Command to perform the same in script is:
Environment.LoadFromFile("FullFilePath")
When required to pass values between applications during /after the test run, this comes in handy.
Using system or user environment variables makes sure the values are available for any application post the test run.
For a novice QTP user updates to this variable can be easy when compared to the QTP environment variables.
Sample Usage as below:
*************************************************************************
'Function to retrieve the value of the DSN from the system variable and use the same for all Database Checkpoints.
'System Variable "DSN" should be created and the should contain the connection string for mcdb98.
'Sample Connection string : DSN=aaaa;NLN=Winsock;NA=11.11.11.11,6000;DB=aaaa;UID=readonly;PWD=readonly
'Change only the instance of DB or the entire network path.
Function EnvironmentVar(DSN)
Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
DSN = WSHShell.Environment.item("DSN")
Environment.Value("DSN") = DSN
Set WSHShell = Nothing
End Function
*************************************************************************
' You liked the post, looking forward to your feedback
** Happy Automating **
No comments:
Post a Comment