Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to Execute a testset from QC using OTA framework
#1
Not Solved
Code:
Dim TSetFact, tsList
Dim theTestSet
Dim tsTreeMgr
Dim tsFolder
Dim Scheduler
Dim execStatus
Dim tdc
Dim nPath
Dim TSTestFact, testList
Dim tsFilter
Dim TSTst

Set tdc = CreateObject("TDAPIOLE80.TDConnection")
If (tdc Is Nothing) Then
MSGBOX  "Connection is not created"
Else
MSGBOX "Connection is created"
End If
tdc.InitConnectionEx "http://qctest:8080/qcbin"
tdc.Login "Username", ""
tdc.Connect "STD", "Projectname"


Set TSetFact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
nPath = "Root\" & Trim("Bui\testset")
MSGBOX nPath
Set tsFolder = tsTreeMgr.NodeByPath(nPath)

If (tsFolder Is Nothing) Then
MSGBOX  "Folder is not found"
Else
MSGBOX "Folder is found"
End If

Set tsList = tsFolder.FindTestSets("Phase")
If tsList.Count > 0 Then
MSGBOX "FindTestSets found more than one test set"
ElseIf tsList.Count < 1 Then
MSGBOX "FindTestSets: test set not found"
End If

Set theTestSet = tsList.Item(1)

'MSGBOX theTestSet.ID
'Set TSTestFact = theTestSet.TSTestFactory
'Set tsFilter = TSTestFact.Filter
'tsFilter.Filter("TC_CYCLE_ID") = theTestSet.ID
'Set testList = TSTestFact.NewList(tsFilter.Text)
'For Each TSTst In testList
'MSGBOX "Name: " & TSTst.Name & " ID: " & TSTst.ID
Set Scheduler = theTestSet.StartExecution("")
Scheduler.RunAllLocally = True
Scheduler.Run
Set execStatus = Scheduler.ExecutionStatus
'MSGBOX  execStatus
'Next

set obj = theTestSet.StartExecution("LocalHost")
obj.RunAllLocally = True
obj.Run()


Set tdc = Nothing


how to select a particular test set and execute it using OTA FRAMEWORK

I have written the above code however i am unable to find out ..how to select the test set and start execution

please help
Reply
#2
Not Solved
Hi,

Please find the code below to find the required test set:

Code:
Dim tdc
Dim runName
Set tdc = CreateObject("tdapiole80.tdconnection")

tdc.InitConnectionEx QCServer
tdc.Login UserName, Password
tdc.Connect DomainName, ProjectName

If (tdc.connected <> True) Then
MsgBox "qc project failed to connect to " & ProjectName
WScript.Quit
End If

Set tfact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
Set tcTreeMgr = tdc.TreeManager
Set TestSetFolder = tsTreeMgr.NodeByPath(<Test_Set_Folder_Path_QC>)

Set TestSetF = TestSetFolder.TestSetFactory 'Retreive test from given folder in test lab
Set aTestSetArray = TestSetF.NewList("")
tsSet_cnt=aTestSetArray.Count
For p=1 to tsSet_cnt   ' Loop through the Test Sets to pick the desired test Set
                Set tstests=aTestSetArray.Item(p)
                TestSet_Name=tstests.Name
                If  TestSet_Name=<Test_Set_Name_QC>  Then
                  <do your next step here>
                End If
Next


Regards,
Parminder
Reply
#3
Not Solved
Hi Parminder,

Thanks for your responce.

However I have modified the below code ...Yet the test script is not executable.Please advice.


I am trying to select a test from the list of tests in a test set and trying to execute it ,however i am unable to select a particular test and execute.


Code:
Dim tdc
Dim runName
Set tdc = CreateObject("TDAPIOLE80.TDConnection")

'###############################################################################################################
tdc.InitConnectionEx "http://qctest:8080/qcbin"
tdc.Login "automation", ""
tdc.Connect "STD", "Project"

If (tdc.connected <> True) Then
MsgBox "qc project failed to connect to " &"Project"
WScript.Quit
End If

Set tfact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
Set tcTreeMgr = tdc.TreeManager
nPath = "Root\" & Trim("Bui\testset")
Set TestSetFolder = tsTreeMgr.NodeByPath(npath)

Set TestSetF = TestSetFolder.TestSetFactory 'Retreive test from given folder in test lab
Set aTestSetArray = TestSetF.NewList("")
tsSet_cnt=aTestSetArray.Count
For i=1 to tsSet_cnt ' Loop through the Test Sets to pick the desired test Set
Set tstests=aTestSetArray.Item(i)
TestSet_Name=tstests.Name
PRINT TestSet_Name
If TestSet_Name= "Creategmailaccount"  Then
Set Scheduler = theTestSet.StartExecution("")
Scheduler.RunAllLocally = True
Scheduler.Run
Set execStatus = Scheduler.ExecutionStatus
MSGBOX execStatus
End If
Next

Thanks!!!
Reply
#4
Not Solved
Hi,

To execute a particular test, use below code;

Code:
Dim tdc
Dim runName
Set tdc = CreateObject("TDAPIOLE80.TDConnection")

'###############################################################################​################################
tdc.InitConnectionEx "http://qctest:8080/qcbin"
tdc.Login "automation", ""
tdc.Connect "STD", "Project"

If (tdc.connected <> True) Then
MsgBox "qc project failed to connect to " &"Project"
WScript.Quit
End If

Set tfact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
Set tcTreeMgr = tdc.TreeManager
nPath = "Root\" & Trim("Bui\testset")
Set TestSetFolder = tsTreeMgr.NodeByPath(npath)

Set TestSetF = TestSetFolder.TestSetFactory 'Retreive test from given folder in test lab
Set aTestSetArray = TestSetF.NewList("")
tsSet_cnt=aTestSetArray.Count
For i=1 to tsSet_cnt ' Loop through the Test Sets to pick the desired test Set
Set tstests=aTestSetArray.Item(i)
TestSet_Name=tstests.Name
PRINT TestSet_Name
If TestSet_Name= "Creategmailaccount" Then
Flag=1
Set TestCaseF = tstests.TSTestFactory 'Retreive Test Cases from the test set
                           Set aTestCaseArray = TestCaseF.NewList("")
test_qc_cnt=aTestCaseArray.count
For n=1 to test_qc_cnt    'Loop through the Test cases in QC to find the same test case as in Excel
                                                                Set  ts_obj=aTestCaseArray.item(n)                                    
                                                                tname_QC=ts_obj.Test.Name
   If Flag=1 Then                                                                              
      runName =ts_obj.RunFactory.UniqueRunName
      Set RunF = ts_obj.RunFactory ' for managing test runs.
     Set theRun = RunF.AddItem(runName)
     theRun.Name =runName 'assign a run name
     theRun.Status =run_status
     theRun.CopyDesignSteps
     theRun.Post
     Flag=0
     End If
Set runStepF = theRun.StepFactory
Set aTestStepArray = runStepF.NewList("")
Set runStepF = theRun.StepFactory
Set aTestStepArray = runStepF.NewList("")
step_cnt=aTestStepArray.Count
For j=1 to step_cnt  ' Loop through steps and update in qc
                                                                                                         Set runStep=aTestStepArray.item(j)
                                                                                                        step_QC=runStep.Name                                          
                                                                                                       runStep.Status ="Passed" 'you can parametrize this value as per your need
                                                                                                       runStep.Post
                                                                                                        Next
End If
Next
Flag=1
Next

I have extracted this code from the one that i used for my scripts and and tried to modify it as per your need. I f you face any issue then let me know.

Regards,
Parminder
Reply
#5
Not Solved
Hi,

Thank you for your Response.I modified the below code and tried executing it in QTP.However no luck.It is creating a Unique run name and it is not executing the test.So Need Assistance as i am new to this OTA framework.

Code:
Dim tdc
Dim runName
Set tdc = CreateObject("TDAPIOLE80.TDConnection")

'###############################################################################​​################################
tdc.InitConnectionEx "http://qcSERVER:8080/qcbin"
tdc.Login "automation", ""
tdc.Connect "STD", "Project"

If (tdc.connected <> True) Then
MsgBox "qc project failed to connect to " &"Project"
WScript.Quit
End If

Set tfact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
Set tcTreeMgr = tdc.TreeManager
nPath = "Root\" & Trim("Bui\testset")
Set TestSetFolder = tsTreeMgr.NodeByPath(npath)

Set TestSetF = TestSetFolder.TestSetFactory 'Retreive test from given folder in test lab
Set aTestSetArray = TestSetF.NewList("")
tsSet_cnt=aTestSetArray.Count
For i=1 to tsSet_cnt ' Loop through the Test Sets to pick the desired test Set
Set tstests=aTestSetArray.Item(i)
TestSet_Name=tstests.Name
PRINT TestSet_Name
If TestSet_Name= "Creategmailaccount" Then
Flag=1
Set TestCaseF = tstests.TSTestFactory 'Retreive Test Cases from the test set
Set aTestCaseArray = TestCaseF.NewList("")
test_qc_cnt=aTestCaseArray.count
For n=1 to test_qc_cnt 'Loop through the Test cases in QC to find the same test case as in Excel
Set ts_obj=aTestCaseArray.item(n)
tname_QC=ts_obj.Test.Name
If tname_QC = "CreateLogin" Then
runName =ts_obj.RunFactory.UniqueRunName
Set RunF = ts_obj.RunFactory ' for managing test runs.
Set theRun = RunF.AddItem(runName)
theRun.Name =runName 'assign a run name
theRun.Status =run_status
theRun.CopyDesignSteps
theRun.Post
Flag=0
End If
Next
Set runStepF = theRun.StepFactory
Set aTestStepArray = runStepF.NewList("")
Set runStepF = theRun.StepFactory
Set aTestStepArray = runStepF.NewList("")
step_cnt=aTestStepArray.Count
For j=1 to step_cnt ' Loop through steps and update in qc
Set runStep=aTestStepArray.item(j)
step_QC=runStep.Name
runStep.Status ="Passed" 'you can parametrize this value as per your need
runStep.Post
Next
Flag=1
End If
Next

Thank you.
Reply
#6
Not Solved
Hi,

Use the below code as it is:

Code:
Dim tdc
Dim runName
Set tdc = CreateObject("TDAPIOLE80.TDConnection")

'###############################################################################​​################################
tdc.InitConnectionEx "http://qctest:8080/qcbin"
tdc.Login "automation", ""
tdc.Connect "STD", "Project"

If (tdc.connected <> True) Then
MsgBox "qc project failed to connect to " &"Project"
WScript.Quit
End If

Set tfact = tdc.TestSetFactory
Set tsTreeMgr = tdc.TestSetTreeManager
Set tcTreeMgr = tdc.TreeManager
nPath = "Root\" & Trim("Bui\testset")
Set TestSetFolder = tsTreeMgr.NodeByPath(npath)

Set TestSetF = TestSetFolder.TestSetFactory 'Retreive test from given folder in test lab
Set aTestSetArray = TestSetF.NewList("")
tsSet_cnt=aTestSetArray.Count
For i=1 to tsSet_cnt ' Loop through the Test Sets to pick the desired test Set
                    Set tstests=aTestSetArray.Item(i)
                    TestSet_Name=tstests.Name
                    PRINT TestSet_Name
                    If TestSet_Name= "Creategmailaccount" Then
                                            Flag=1
                                            Set TestCaseF = tstests.TSTestFactory 'Retreive Test Cases from the test set
                                            Set aTestCaseArray = TestCaseF.NewList("")
                                            test_qc_cnt=aTestCaseArray.count
                                            For n=1 to test_qc_cnt 'Loop through the Test cases in QC to find the same test case as in Excel
                                                        Set ts_obj=aTestCaseArray.item(n)
                                                        tname_QC=ts_obj.Test.Name
                                                        If  tname_QC="CreateLogin" Then                                                        
                                                                If Flag=1 Then
                                                                runName =ts_obj.RunFactory.UniqueRunName
                                                                Set RunF = ts_obj.RunFactory ' for managing test runs.
                                                                Set theRun = RunF.AddItem(runName)
                                                                theRun.Name =runName 'assign a run name
                                                                theRun.Status ="Passed" 'you can parametrize this value as per your need
                                                                theRun.CopyDesignSteps
                                                                theRun.Post
                                                                Flag=0
                                                                End If
                                                                Set runStepF = theRun.StepFactory
                                                                Set aTestStepArray = runStepF.NewList("")
                                                                Set runStepF = theRun.StepFactory
                                                                Set aTestStepArray = runStepF.NewList("")
                                                                step_cnt=aTestStepArray.Count
                                                                        For j=1 to step_cnt ' Loop through steps and update in qc
                                                                        Set runStep=aTestStepArray.item(j)
                                                                        step_QC=runStep.Name
                                                                        runStep.Status ="Passed" 'you can parametrize this value as per your need
                                                                        runStep.Post
                                                                        Next        
                                                        End If                                                        
                                             Next
                                Flag=1
                  End If                    
Next

Hope this will solve your problem.

Regards,
Parminder
Reply
#7
Not Solved
Hi Parminder,

Thank you once again and the code is working perfectly fine without any errors.However I had a couple of questions.

1. When we execute a test,will it open the test in QTP and execute or it will run in background.(Since the script is not launching the web application)

2. After the execution of the above script,it shows status as "passed" in QC however once i try launching the report,it shows a pop up "cannot download report".- will the report be displayed or not.

I have also uploaded the snap shot of the same.

Thank you!!!!


Attached Files
.doc   Screen shot.doc (Size: 123 KB / Downloads: 274)
Reply
#8
Not Solved
Hi,

1. There is no need of QTP for this script. You can save your script as .vbs file and just double click it when you want to run it. It will run in the background. You can put a message box at the end of the script to know that the script is finished.

2.There will be no report to show as there is no real execution of tests only field values are getting changed. Launch Report is coming as your tests are qtp tests. However if you put manual tests in the test set, then you will see no Launch Report icon after execution.

This OTA approach is useful if you have your test results in an external file e.g. excel and you want to update these results in QC.

Regards,
Parminder
Reply
#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
#10
Not Solved
Hi,

My requirement was to update the result in QC from excel file(this file contained the results from selenium scripts execution). So i implemented that only using OTA. Don't know about the real execution.

Maybe someone else here can help you out Sad

Regards,
Parminder
Reply


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

Forum Jump:


Users browsing this thread: 1 Guest(s)