Environment Object Creation In QTP

Environment Object Creation In QTP , VBScript objects used in qtp descriptive programming.
'************************************************************************************************************************
'Description:
'
'This example sends parameters to a test by defining environment variables before running the test.
'It also lists the user and operating system from each test run in the test's description.
'
'Assumptions:
'There is no unsaved test currently open in QuickTest.
'For more information, see the example for the Test.SaveAs method.
'When QuickTest opens, it loads the add-ins required for the test.
'For more information, see the example for the Test.GetAssociatedAddins method.
'************************************************************************************************************************

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtOptions 'As QuickTest.RunResultsOptions ' Declare the Run Results Options object variable
Dim strOS
Dim strUserName

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object
qtApp.Launch ' Start QuickTest
qtApp.Visible = True ' Make the QuickTest application visible

' Open the test
qtApp.Open "C:\Tests\Test1", False ' Open a test named "Test1"

' Set some environment variables
qtApp.Test.Environment.Value("Root") = "C:\" ' Set the "Root" environment variable. Note: 'Value' is a default property and can be omitted.
qtApp.Test.Environment.Value("Password") = "not4you" ' Set the "Password" environment variable
qtApp.Test.Environment.Value("Days") = 14 ' Set the "Days" environment variable
' Run the test
Set qtOptions = CreateObject("QuickTest.RunResultsOptions") ' Create a Results Option object
qtOptions.ResultsLocation = "" ' Set the Results location to temporary location
qtApp.Test.Run qtOptions, True ' Run the test and wait for it to finish before continuing the automation script

' Concatenate data stored in the environment to the description
strOS = qtApp.Test.Environment.Value("OS") ' Return the "OS" environment variable
strUserName = qtApp.Test.Environment.Value("UserName") ' Return the "UserName" environment variable
qtApp.Test.Description = qtApp.Test.Description & vbNewLine & _
       "Tested on: " & Now & vbNewLine & _
       "Platform: " & strOS & vbNewLine & _
       "By user: " & strUserName & vbNewLine & _
       "-------------------------" & vbNewLine ' Add the current time, OS, and user name to the test's description

qtApp.Test.Save ' Save the test

qtApp.Quit ' Exit QuickTest
Set qtOptions = Nothing ' Release the Run Results Options object
Set qtApp = Nothing ' Release the Application object


The below stuff is very important and very frequently used by any QTP programmer in Object identification using QTP.

0 comments:

Post a Comment