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.

4 comments:

  1. Great blog thanks for sharing Looking for the best creative agency to fuel new brand ideas? Adhuntt Media is not just a digital marketing company in chennai. We specialize in revamping your brand identity to drive in best traffic that converts.

    ReplyDelete
  2. Nice blog thanks for sharing Growing your own plant comes with its own challenges and responsibilities. This is why you need a plant nursery in chennai who is ready to help you out throughout the way and guide you through the hurdles of growing a plant - Enter Karuna Nursery Gardens.

    ReplyDelete
  3. Great blog thanks for sharing Pixies Beauty Shop is unlike any of the other cosmetic shops in Chennai. With tons of exclusive imported brands to choose from and the best value, this is the best shopping destination for your personal and salon needs.

    ReplyDelete