Showing posts with label Automation Object Model Scripts. Show all posts
Showing posts with label Automation Object Model Scripts. Show all posts

28 Jun 2013

Automation Object Model Scripts

Open QTP and Connect to Quality Center

' Declare the Application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Make changes in a test on Quality Center with version control

' Connect to Quality Center 

qtApp.TDConnection.Connect "QC URL", "DOMAIN Name", "Project Name", "User Name", 

"Password", False  

' If connection is successful 

If qtApp.TDConnection.IsConnected Then  

   MsgBox "Succesfully connected to Quality Center" 

Else 

   MsgBox "Cannot connect to Quality Center" 

End If 

' Exit QuickTest 

qtApp.Quit  

' Release the Application object 

Set qtApp = Nothing  

Start QTP and open New test  

' Declare the application object variable 

Dim qtApp  

' Create the application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Open a new test 

qtApp.New  

' Release the Application object 


Set qtApp = Nothing  

 Start QTP, open an existing test and Run the Test 

' Declare the application object variable 

Dim qtApp 

Dim qtTest 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Set QuickTest run options 

qtApp.Options.Run.ImageCaptureForTestResults = "OnError" 

qtApp.Options.Run.RunMode = "Fast"  

qtApp.Options.Run.ViewResults = False 

' Open the test in read-only mode 

qtApp.Open "C:\Tests\Test1", True  

' Set run settings for the test 

Set qtTest = qtApp.Test 

' Instruct QuickTest to perform next step when error occurs 

qtTest.Settings.Run.OnError = "NextStep"  

' Run the test 

qtTest.Run  

' Check the results of the test run 

MsgBox qtTest.LastRunResults.Status  

' Close the test 

qtTest.Close  

' Release the Test object 

Set qtTest = Nothing  

' Release the Application object 


Set qtApp = Nothing  

Start QTP, open an existing test, Run the Test with configured Run and Result options 

' Declare the application object variable 

Dim qtApp 

Dim qtTest 

Dim qtResultsOpt 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  
  
' Start QuickTest 

qtApp.Launch  

' Make the QuickTest application visible 

qtApp.Visible = True  

' Set QuickTest run options 

qtApp.Options.Run.ImageCaptureForTestResults = "OnError" 

qtApp.Options.Run.RunMode = "Fast" 

qtApp.Options.Run.ViewResults = False 

' (True) Open the test in read-only mode 

qtApp.Open "C:\Tests\Test1", True  

' Set run settings for the test 

Set qtTest = qtApp.Test 

' Run only iterations 2 to 4 

qtTest.Settings.Run.IterationMode = "rngIterations"  

qtTest.Settings.Run.StartIteration = 2 

qtTest.Settings.Run.EndIteration = 4 

' Instruct QuickTest to perform next step when error occurs 

qtTest.Settings.Run.OnError = "NextStep"  

' Create the Run Results Options object 

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions")  

' Set the results location 

qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1"  

' Run the test 

qtTest.Run qtResultsOpt  

' Check the results of the test run 

MsgBox qtTest.LastRunResults.Status  

' Close the test 

qtTest.Close  

' Release the Run Results Options object 

Set qtResultsOpt = Nothing  

' Release the Test object 

Set qtTest = Nothing  

' Release the Application object  


Set qtApp = Nothing

 Start QTP, open an existing test, associate libraries and save the test 

' Declare the application object variable 

Dim qtApp 

Dim qtLibraries 

Dim lngPosition 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Launch QuickTest 

qtApp.Launch  

' Set QuickTest to be visible 

qtApp.Visible = True  

' Open a test 

qtApp.Open "C:\Tests\Test1", False, False  

' Get the libraries collection object 

Set qtLibraries = qtApp.Test.Settings.Resources.Libraries  

' Add Utilities.vbs if it's not in the collection 

' If the library cannot be found in the collection 
  
If qtLibraries.Find("C:\Utilities.vbs") = -1 Then  

   ' Add the library to the collection 

    qtLibraries.Add "C:\Utilities.vbs", 1  

End If 

' Save the test 

qtApp.Test.Save  

' Quit QuickTest 

qtApp.Quit  

' Release the test's library’s collection 

Set qtLibraries = Nothing  

' Release the Application object 


Set qtApp = Nothing  

Start QTP, open an existing test, associate Object Repositories and save the test
  
' Declare the application object variable 

Dim qtApp 

Dim qtRepositories 

Dim lngPosition 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Launch QuickTest 

qtApp.Launch  

' Set QuickTest to be visible 

qtApp.Visible = True  

' Open a test and get the "Login" action's object repositories collection 

qtApp.Open "C:\Tests\Test1", False, False   

' Get the object repositories collection object of the "Login" action 

Set qtRepositories = qtApp.Test.Actions("Login").ObjectRepositories  

' Add MainApp.tsr if it's not already in the collection 

' If the repository cannot be found in the collection 

If qtRepositories.Find("C:\MainApp.tsr") = -1 Then  

   ' Add the repository to the collection 

   qtRepositories.Add "C:\MainApp.tsr", 1  

End If 

'Save the test and close QuickTest 

qtApp.Test.Save 

qtApp.Quit 

' Release the action's shared repositories collection 

Set qtRepositories = Nothing  

' Release the Application object 


Set qtApp = Nothing  

Open and minimize QTP Window  

' Declare the application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Start QuickTest 

qtApp.Launch  

' Make the QuickTest window visible 

qtApp.Visible = True  

' Maximize the QuickTest window 

qtApp.WindowState = "Minimized"   

' Release the Application object 


Set qtApp = Nothing  

Start QTP, Open an Existing Test and Get All Available Action Names From the Test
  
' Declare the application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application")  

' Launch QuickTest   

qtApp.Launch  

' Set QuickTest to be visible 

qtApp.Visible = True  

' Open a test 

qtApp.Open "C:\Tests\Test1", False, False 

oActCount=qtApp.Test.Actions.Count 

For iCounter=1 to oActCount 

     ' Get the first action in the test by index (start from 1) 

     MsgBox qtApp.Test.Actions(iCounter).Name 

Next 

'Close QuickTest 

qtApp.Quit  

' Release the Application object 


Set qtApp = Nothing

Start QTP with specified views 

' Declare the application object variable 

Dim qtApp 

' Create the Application object 

Set qtApp = CreateObject("QuickTest.Application") 

' Start QuickTest 

qtApp.Launch  

' Display the Expert View 

qtApp.ActivateView "ExpertView"  

' Display the Active Screen pane 

qtApp.ShowPaneScreen "ActiveScreen", True  

' Hide the Data Table pane 

qtApp.ShowPaneScreen "DataTable", False  

' Display the Debug Viewer pane 

qtApp.ShowPaneScreen "DebugViewer", True  

' Maximize the QuickTest window 

qtApp.WindowState = "Maximized"  

' Make the QuickTest window visible 

qtApp.Visible = True  

' Release the Application object 


Set qtApp = Nothing