Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Execute a testset from QC using OTA framework
#9
Not Solved
Hi Parminder,

Is there a way to do real execution of tests?

Since i saw this piece of code i.e "Running the test instances in a test set locally, remotely, or as planned" in OTA sample codes.So thought there is way to do real execution of a test from QC.

Code:
Public Sub RunTestSet(tsFolderName As String, tSetName As String, _
        HostName As String, runWhere As Integer)

' This example show how to run a test set in three different ways:
' * Run all tests on the local machine (where this code runs).
' * Run the tests on a specified remote machine.
' * Run the tests on the hosts as planned in the test set.
    Dim TSetFact As TestSetFactory, tsList As List
    Dim theTestSet As TestSet
    Dim tsTreeMgr As TestSetTreeManager
    Dim tsFolder As TestSetFolder
    Dim Scheduler As TSScheduler
    Dim execStatus As ExecutionStatus

    On Error GoTo RunTestSetErr
    errmsg = "RunTestSet"
' Get the test set tree manager from the test set factory.
    'tdc is the global TDConnection object.
    Set TSetFact = tdc.TestSetFactory
    Set tsTreeMgr = tdc.TestSetTreeManager
' Get the test set folder passed as an argument to the example code.
    Dim nPath$
    nPath = "Root\" & Trim(tsFolderName)
    On Error Resume Next
    Set tsFolder = tsTreeMgr.NodeByPath(nPath)

    If tsFolder Is Nothing Then
        err.Raise vbObjectError + 1, "RunTestSet", "Could not find folder " & nPath
        GoTo RunTestSetErr
    End If
    On Error GoTo RunTestSetErr
' Search for the test set passed as an argument to the example code.
    Set tsList = tsFolder.FindTestSets(tSetName)
    If tsList.Count > 1 Then
        MsgBox "FindTestSets found more than one test set: refine search"
    ElseIf tsList.Count < 1 Then
        MsgBox "FindTestSets: test set not found"
    End If

    Set theTestSet = tsList.Item(1)
    Debug.Print theTestSet.ID

' Start the scheduler on the local machine.
    Set Scheduler = theTestSet.StartExecution("")

'Set up for the run depending on where the test instances
' are to execute.

    Select Case runWhere

        Case RUN_LOCAL
        ' Run all tests on the local machine.
            Scheduler.RunAllLocally = True
        Case RUN_REMOTE
        ' Run tests on a specified remote machine.
            Scheduler.TdHostName = HostName
            ' RunAllLocally must not be set for
            ' remote invocation of tests.
            ' Do not do this:
            ' Scheduler.RunAllLocally = False
        Case RUN_PLANNED_HOST
        ' Run on the hosts as planned in the test set.
            Dim TSTestFact As TSTestFactory, testList As List
            Dim tsFilter As TDFilter
            Dim TSTst As TSTest
        ' Get the test instances from the test set.
            Set TSTestFact = theTestSet.TSTestFactory
            Set tsFilter = TSTestFact.Filter
            tsFilter.Filter("TC_CYCLE_ID") = theTestSet.ID
            Set testList = TSTestFact.NewList(tsFilter.Text)
            Debug.Print "Test instances and planned hosts:"
        'For each test instance, set the host to run depending
        ' on the planning in the test set.
            For Each TSTst In testList
                Debug.Print "Name: " & TSTst.Name & " ID: " & TSTst.ID & " Planned Host: " & TSTst.HostName
                Scheduler.RunOnHost(TSTst.ID) = TSTst.HostName
            Next TSTst

            Scheduler.RunAllLocally = False
    End Select
' Run the tests.
    Scheduler.Run
' Get the execution status object.
    Set execStatus = Scheduler.ExecutionStatus
' Track the events and statuses.
    Dim RunFinished As Boolean, iter As Integer, i As Integer
    Dim ExecEventInfoObj As ExecEventInfo, EventsList As List
    Dim TestExecStatusObj As TestExecStatus
    While ((RunFinished = False) And (iter < 100))
        iter = iter + 1
        execStatus.RefreshExecStatusInfo "all", True
        RunFinished = execStatus.Finished
        Set EventsList = execStatus.EventsList

        For Each ExecEventInfoObj In EventsList
            Debug.Print Tab; "Event: " & ExecEventInfoObj.EventDate & " " & _
                    ExecEventInfoObj.EventTime & " " & _
                    "Event Type: " & ExecEventInfoObj.EventType & " [Event types: " & _
                    "1-fail, 2-finished, 3-env fail, 4-timeout, 5-manual]"
        Next

        Debug.Print Tab; execStatus.Count & " exec status"
        For i = 1 To execStatus.Count
            Set TestExecStatusObj = execStatus.Item(i)
            Debug.Print Tab; "Iteration " & iter & " Status: " & _
                        " Test " & TestExecStatusObj.TestID & _
                        " ,Test instance " & TestExecStatusObj.TestInstance & _
                        " ,order " & TestExecStatusObj.TSTestID & " " & _
                        TestExecStatusObj.Message & ", status=" & _
                        TestExecStatusObj.Status
        Next i
        'Sleep() has to be declared before it can be used.
        'This is the module level declaration of Sleep():
        'Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
        Sleep (5000)

    Wend 'Loop While execStatus.Finished = False

    Debug.Print "Scheduler finished around " & CStr(Now)
    Debug.Print

Exit Sub
RunTestSetErr:
    ErrHandler err, err.Description, errmsg, NON_FATAL_ERROR
End Sub

Thank you!!!
Reply


Messages In This Thread
RE: How to Execute a testset from QC using OTA framework - by AutomationTester2011 - 09-08-2011, 10:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Execute button of putton won't be clicke automaticly in UFT (VB) MarUFT 3 2,455 11-21-2016, 04:22 PM
Last Post: Ankur
  Not able to execute script shanthalaAR 0 1,943 06-27-2015, 03:53 AM
Last Post: shanthalaAR
  Is there a possible way to execute sql in QTP using 'WITH' clause shruthic 0 2,993 04-26-2014, 11:42 PM
Last Post: shruthic
  Execute scripts sherst 0 2,836 01-11-2013, 01:46 AM
Last Post: sherst
  execute file rjkmr.aiht 6 4,995 05-16-2012, 03:09 PM
Last Post: rjkmr.aiht

Forum Jump:


Users browsing this thread: 1 Guest(s)