Sunday, June 9, 2013

Open a Test with Associated Add-ins Loaded

In this post i am going to describe how to automatically load all addin that are associated with test only.The code will open the test at run time and opens associated addins.
'This example opens a test and loads all the add-ins associated with the test.

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim blnNeedChangeAddins ' Declare a flag for indicating whether the test's 

                        'associated add-ins are currently loaded
Dim arrTestAddins ' Declare the variable for storing the test's associated add-ins

Set qtApp = CreateObject("QuickTest.Application") ' Create the Application object

' Create an array containing the list of addins associated with this test
'Change Location as per your test
arrTestAddins = qtApp.GetAssociatedAddinsForTest("C:\Tests\Test1")

' Check if all required add-ins are all already loaded
blnNeedChangeAddins = False ' Assume no change is necessary
For Each testAddin In arrTestAddins ' Iterate over the test's associated 

                                    ' add-ins list
    If qtApp.Addins(testAddin).Status <> "Active" Then ' If an associated add-in is 

                                                        ' not loaded
        blnNeedChangeAddins = True ' Indicate that a change in the loaded add-ins 

                                   'is necessary
        Exit For ' Exit the loop
    End If

If qtApp.Launched And blnNeedChangeAddins Then
        qtApp.Quit ' If a change is necessary, exit QuickTest to 

                   '  modify the loaded add-ins
End If

If blnNeedChangeAddins Then
    Dim blnActivateOK

'Load the add-ins associated with the test and check whether they load successfully.
    blnActivateOK = qtApp.SetActiveAddins(arrTestAddins, errorDescription)
    If Not blnActivateOK Then ' If a problem occurs while loading the add-ins
        MsgBox errorDescription ' Show a message containing the error
    WScript.Quit ' And end the automation program.
    End If
End If

If Not qtApp.Launched Then ' If QuickTest is not yet open
    qtApp.Launch ' Start QuickTest (with the correct add-ins loaded)
End If
qtApp.Visible = True ' Make the QuickTest application visible

qtApp.Open "C:\Tests\Test1" ' Open the test
Set qtApp = Nothing ' Release the Application object

Wednesday, June 5, 2013

QTP || Check the Test Run Result using VB Script

'This example opens a test, configures run options and settings,
'runs the test, and then checks the results of the test run.

Dim qtApp 'As QuickTest.Application ' Declare the Application object variable
Dim qtTest 'As QuickTest.Test ' Declare a Test object variable
Dim qtResultsOpt 'As QuickTest.RunResultsOptions ' Declare a Run Results Options object variable

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

' Set QuickTest run options

qtApp.Options.Run.ImageCaptureForTestResults = "OnError"

qtApp.Options.Run.RunMode = "Fast"
qtApp.Options.Run.ViewResults = False

qtApp.Open "C:\Tests\Test1", True ' Open the test in read-only mode

' set run settings for the test
Set qtTest = qtApp.Test
qtTest.Settings.Run.IterationMode = "rngIterations" ' Run only iterations 2 to 4
qtTest.Settings.Run.StartIteration = 2
qtTest.Settings.Run.EndIteration = 4
qtTest.Settings.Run.OnError = "NextStep" ' Instruct QuickTest to perform next step when error occurs

Set qtResultsOpt = CreateObject("QuickTest.RunResultsOptions") ' Create the Run Results Options object
qtResultsOpt.ResultsLocation = "C:\Tests\Test1\Res1" ' Set the results location

qtTest.Run qtResultsOpt ' Run the test

MsgBox qtTest.LastRunResults.Status ' Check the results of the test run
qtTest.Close ' Close the test

Set qtResultsOpt = Nothing ' Release the Run Results Options object
Set qtTest = Nothing ' Release the Test object
Set qtApp = Nothing ' Release the Application object

Monday, June 3, 2013

VBA code for Generating defects from QC without Queries

'Below mentioned is the code that can be utilized to get connected with QC and also generating the defects from 'the QC using VBA code
'This function will help you to get connected with Qualitty Center
Public Function QualityCenterConnection(ByVal qserver, qDomainName, qProjectname)
qusername = "username"
qpassword = "password"
Dim QCConnection
'Return the TDConnection object.
Set QCConnection = CreateObject("TDApiOle80.TDConnection")

QCConnection.InitConnectionEx qserver

'Login into Username and password

' Set the column names.

QCConnection.login qusername, qpassword
''Pass Domain Name and Project Name
QCConnection.Connect qDomainName, qProjectname
Set ConnectToQC = QCConnection

End function

Public Function exportreport()
Dim qserver As String
Dim qusername As String
Dim qpassword As String

qserver = "http://server name/qcbin"

qDomainName = "Domain Name"

qProjectname = "Project Name"

Dim QCConnection

Set QCConnection = QualityCenterConnection(qserver, qDomainName, qProjectname)

Set bfact = QCConnection.BugFactory

' Get a list of all the defects.
Dim BugFactory, BugList
Set BugFactory = QCConnection.BugFactory
Set BugList = BugFactory.NewList("")
'You can choose any other value that you want as per your need and requirements.
Cells(1, 1).Value = "Bug Id"
Cells(1, 2).Value = "Summary"
Cells(1, 3).Value = "Detected By"
Cells(1, 4).Value = "Priority"
Cells(1, 5).Value = "Status"
Cells(1, 6).Value = "Assigned To"
' Retrieve the values of each bug in excel sheet
Dim Bug, Row
Row = 2
For Each Bug In BugList
   Cells(Row, 1).Value = Bug.Field("BG_BUG_ID")
   Cells(Row, 2).Value = Bug.Summary
   Cells(Row, 3).Value = Bug.DetectedBy
   Cells(Row, 4).Value = Bug.Priority
   Cells(Row, 5).Value = Bug.Status
   Cells(Row, 6).Value = Bug.AssignedTo
     Row = Row + 1

End function