' Scripted by - Srihari Vanumu
' Application - Application LifeCycle Management 11
' Version - 1.0
' Business Flows provided - Yes
' Creation date : 13-Jan-2014
' Script flow--->
' 1) Connect to a project of the ALM application
' 2) Get Access to Customization
' 3) Retrieve all the Users under this project
' 4) Iterate through all the Users and perform the below operation based on a business condition
' 5) Business Condition: If Inactive role is not present for current user ; assign it!!
' Remove all the existing roles except TDAdmin.
' 6) Commit the changes performed to database and application.
' 7) Write the Progress status to Log File for Verfication Purpose.
Imports TDAPIOLELib

Module Module1
Sub Main()
Dim tdc
Dim custom As Customization
Dim users As CustomizationUsers
Dim eachuser As CustomizationUser
Dim GetAllCustomUsers As List
Dim GetAllGroupList As List
Dim fso, f
Dim com As TDAPIOLELib.Command
Dim RecSet As TDAPIOLELib.Recordset
Dim i As Integer
i = 1
Dim Count As Integer
fso = CreateObject("Scripting.FileSystemObject")
f = fso.OpenTextFile("C:\TEMP\Status_Log_File.txt", 2, True)
tdc = CreateObject("TDApiOle80.TDConnection")
tdc.InitConnectionEx("http://almdev/qcbin/")
'Note: For Quality Center, connect by using the URL below:
'td.InitConnectionEx "http://:port/qcbin"
tdc.ConnectProjectEx("DEFAULT", "M2_Users", "svanumu", "Password")
' Setting and executing the SQL
com = tdc.Command
com.CommandText = "select count(*) from users"
RecSet = com.Execute
' Displaying the 2nd column data
For Count = 1 To RecSet.RecordCount
Console.WriteLine("Total Count of Users in this Project::::::" + RecSet.FieldValue(0))
f.WriteLine("Total Count of Users in this Project::::::" + RecSet.FieldValue(0))
RecSet.Next()
Next
custom = tdc.Customization
users = custom.Users
GetAllCustomUsers = users.Users()
f.WriteLine("Task Started !!!! Below are the Operations to be Performed !!!!")
f.WriteLine("1) Connect to a project of the ALM application")
f.WriteLine("2) Get Access to Customization")
f.WriteLine("3) Retrieve all the Users under this project")
f.WriteLine("4) Iterate through all the Users and perform the below operation based on a business condition")
f.WriteLine("4.1) Business Condition: If Inactive role is not present for current user ; assign it!!")
f.WriteLine("4.2) Remove all the existing roles except TDAdmin.")
f.WriteLine("5) Commit the changes performed to database and application.")
f.WriteLine("6) Write the Progress status to Log File for Verfication Purpose. ")
Console.WriteLine("******************************PROGRAM EXECUTION STARTED************************************************************")
f.WriteLine("******************************PROGRAM EXECUTION STARTED************************************************************")
For Each eachuser In GetAllCustomUsers

'************************************************************************************************************************
' If eachuser.Name = "ragupta" Then

' Above Line If should be removed in case if you want to run this program for all the users
' Console.WriteLine("Adding View Only role to matre and removing all the other roles")
' Above Line Exit For should be removed in case if you want to run this program for all the users

Console.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::STARTED")
f.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::STARTED")
If eachuser.Name = "_system_user_" Then
Continue For
Console.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
f.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
End If
If eachuser.Name = "admin" Then
Continue For
Console.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
f.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
End If
If eachuser.Name = "svc-qcaccess" Then
Continue For
Console.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
f.WriteLine(eachuser.Name.ToString + "|" + "Skipped")
End If
Console.WriteLine(eachuser.Name.ToString + "|" + "Activity Started")
f.WriteLine(eachuser.Name.ToString + "|" + "Activity Started")

'***********************IF USER DOESNOT HAVE VIEW ONLY ROLE ASSIGN THAT ROLE*********************************************
If eachuser.InGroup("Inactive") = False Then
eachuser.AddToGroup("Inactive")
Console.WriteLine(eachuser.Name.ToString + "|" + "Inactive" + "|" + "Added")
f.WriteLine(eachuser.Name.ToString + "|" + "Inactive" + "|" + "Added")
End If

If eachuser.InGroup("View Only") = True Then
eachuser.RemoveFromGroup("View Only")
Console.WriteLine(eachuser.Name.ToString + "|" + "View Only" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "View Only" + "|" + "Removed")
End If

If eachuser.InGroup("Business Owner") = True Then
eachuser.RemoveFromGroup("Business Owner")
Console.WriteLine(eachuser.Name.ToString + "|" + "Business Owner" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Business Owner" + "|" + "Removed")
End If
If eachuser.InGroup("Business Reviewer") Then
eachuser.RemoveFromGroup("Business Reviewer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Business Reviewer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Business Reviewer" + "|" + "Removed")
End If
If eachuser.InGroup("Defect Resolver") Then
eachuser.RemoveFromGroup("Defect Resolver")
Console.WriteLine(eachuser.Name.ToString + "|" + "Defect Resolver" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Defect Resolver" + "|" + "Removed")
End If
If eachuser.InGroup("Developer") Then
eachuser.RemoveFromGroup("Developer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Developer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Developer" + "|" + "Removed")
End If
If eachuser.InGroup("eApprove Administrator") Then
eachuser.RemoveFromGroup("eApprove Administrator")
Console.WriteLine(eachuser.Name.ToString + "|" + "eApprove Administrator" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "eApprove Administrator" + "|" + "Removed")
End If
If eachuser.InGroup("Lead Test Manager") Then
eachuser.RemoveFromGroup("Lead Test Manager")
Console.WriteLine(eachuser.Name.ToString + "|" + "Lead Test Manager" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Lead Test Manager" + "|" + "Removed")
End If
If eachuser.InGroup("Project Manager") Then
eachuser.RemoveFromGroup("Project Manager")
Console.WriteLine(eachuser.Name.ToString + "|" + "Project Manager" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Project Manager" + "|" + "Removed")
End If
If eachuser.InGroup("QATester") Then
eachuser.RemoveFromGroup("QATester")
Console.WriteLine(eachuser.Name.ToString + "|" + "QATester" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "QATester" + "|" + "Removed")
End If
If eachuser.InGroup("Quality") Then
eachuser.RemoveFromGroup("Quality")
Console.WriteLine(eachuser.Name.ToString + "|" + "Quality" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Quality" + "|" + "Removed")
End If
If eachuser.InGroup("Technical Reviewer") Then
eachuser.RemoveFromGroup("Technical Reviewer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Technical Reviewer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Technical Reviewer" + "|" + "Removed")
End If
If eachuser.InGroup("Test Analyst") Then
eachuser.RemoveFromGroup("Test Analyst")
Console.WriteLine(eachuser.Name.ToString + "|" + "Test Analyst" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Test Analyst" + "|" + "Removed")
End If
If eachuser.InGroup("Test Automation") Then
eachuser.RemoveFromGroup("Test Automation")
Console.WriteLine(eachuser.Name.ToString + "|" + "Test Automation" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Test Automation" + "|" + "Removed")
End If
If eachuser.InGroup("Test Manager") Then
eachuser.RemoveFromGroup("Test Manager")
Console.WriteLine(eachuser.Name.ToString + "|" + "Test Manager" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Test Manager" + "|" + "Removed")
End If
If eachuser.InGroup("Tester") Then
eachuser.RemoveFromGroup("Tester")
Console.WriteLine(eachuser.Name.ToString + "|" + "Tester" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Tester" + "|" + "Removed")
End If
If eachuser.InGroup("Viewer") Then
eachuser.RemoveFromGroup("Viewer")
Console.WriteLine(eachuser.Name.ToString + "|" + "Viewer" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Viewer" + "|" + "Removed")
End If
If eachuser.InGroup("Requirement Author") Then
eachuser.RemoveFromGroup("Requirement Author")
Console.WriteLine(eachuser.Name.ToString + "|" + "Requirement Author" + "|" + "Removed")
f.WriteLine(eachuser.Name.ToString + "|" + "Requirement Author" + "|" + "Removed")
End If
' custom.Commit()
Console.WriteLine(eachuser.Name.ToString + "|" + "Changes Commited")
f.WriteLine(eachuser.Name.ToString + "|" + "Changes Commited")

Console.WriteLine(eachuser.Name.ToString + "|" + "Activity Ended")
f.WriteLine(eachuser.Name.ToString + "|" + "Activity Ended")

Console.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::ENDED")
f.WriteLine("PROCESS FOR::::" + eachuser.Name.ToString + ":::::User::" + i.ToString + ":::::ENDED")

i = i + 1

' Exit For
' Above Line Exit For should be removed in case if you want to run this program for all the users
' End If
' Above Line End If should be removed in case if you want to run this program for all the users
'************************************************************************************************************************
Next
custom.Commit()
Console.WriteLine("Changes Commited for All Users")
f.WriteLine("Changes Commited for All Users")
Console.WriteLine("******************************PROGRAM EXECUTION COMPLETED************************************************************")
f.WriteLine("******************************PROGRAM EXECUTION COMPLETED************************************************************")
f.Close()
fso = Nothing
f = Nothing
custom = Nothing
users = Nothing
eachuser = Nothing
GetAllCustomUsers = Nothing
GetAllGroupList = Nothing
tdc = Nothing
Console.ReadLine()
End Sub
End Module

Advertisements

Imports TDAPIOLELib

Module Module1

Sub Main()

Dim tdc, msg
tdc = CreateObject(“TDApiOle80.TDConnection”)
tdc.InitConnectionEx(“http://almdev/qcbin”)
‘Note: For Quality Center, connect by using the URL below:
‘td.InitConnectionEx “http://:port/qcbin”
tdc.ConnectProjectEx(“DEFAULT”, “AMGEN_ERP”, “svanumu”, “XYZ”)

/******** CODE FROM OTA FILE *********************/
Dim custom As Customization
custom = tdc.Customization
Dim lists As CustomizationLists
lists = custom.Lists
‘Try
lists.AddList(“Srihari”)
‘Catch
‘End Try
custom.Commit()

/******* END OF CODE FROM OTA FILE ****************/

End Sub

End Module

Download latest loadrunner(tool) software from http://www.hp.com/go/loadrunner and understand this tool by following the Tutorial and VUGEN Guide/Help file which gets installed as a part of this software.

If your company sponsor; you can get HP trainings by registering here http://h20546.www2.hp.com/main/training/course_list.cfm?sitepick=US&ProductID=10

Below are some of the sites I found very interesting; You can go through these below websites for understanding performance testing concepts and loadrunner tool.

1) http://www.youtube.com/watch?v=gxnmpFF5-M0&list=PLwbuZz2PgXBpSNCEevVAwO4P5rRzPKp7O

2) http://motevich.blogspot.com/2008/01/loadrunner-tutorials.html

3) http://www.joecolantonio.com/2011/07/05/performance-testing-what-is-throughput/

4) http://www.myloadtest.com/tag/vugen/

5) http://harinderseera.blogspot.com/2010/12/loadrunner-script-for-soap-over-jms.html

7) http://www.perftestplus.com/pubs.htm

8) http://www.wilsonmar.com/

9) http://www.headwired.com/tag/vugen/

10) http://blog.testsautomation.com/2010/12/how-to-debug-loadrunner-script/

11) http://sramanapudi.blogspot.com/2013/04/web-htmlhttp-basic-example-of-error.html#!/2013/04/web-htmlhttp-basic-example-of-error.html

12) *******************http://easyloadrunner.blogspot.com/*************************excellent********

13) http://www.perftesting.co.uk/loadtesttools/loadrunner/

14) http://www.jds.net.au/tech-tips/top-loadrunner-blogs/

15) http://h30499.www3.hp.com/t5/LoadRunner-Performance-Center/tkb-p/lr_pc_tkb

16) http://h30499.www3.hp.com/t5/Best-Practices-and-Methodology/bd-p/sws-APP_Perf_VaL_BP

In order to play with loadrunner Vugen scripts you should be good in programming languages such as C, VB, J2SE etc

Below are some useful video tutorials:

http://www.learnerstv.com/Free-Computer-Science-video-lecture-courses.htm

http://thenewboston.org/tutorials.php

http://java2s.com ( Covers all the programming languages and SQL in depth ).

While Practising these programming languages if you get any doubts you can ask here http://stackoverflow.com/

In order to understand concepts of performance testing ; we should be very good understanding of all the Software / Hardware / Network components in AUT Infrastructure.

Identification of bottle necks and other concepts will come only through experience and if we work under mentor and person who have experience in this field.

You should learn all the concepts of Operating System, Memory , CPU, Communication Protocols etc.

If you have any doubts or questions in loadrunner you can ask here.

http://h30499.www3.hp.com/t5/LoadRunner-Support-Forum/bd-p/sws-LoadRunner_SF

https://groups.google.com/forum/#!forum/LR-LoadRunner

http://groups.yahoo.com/neo/groups/LoadRunner/info


'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'" Script Description :
'"
'"
'" Script Author :
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Init()

'" TO DO: Place your initialization code here

lr.log_message " +++++++++++++++ vuser_init(): Script Starting +++++++++++++++ "

Init = lr.PASS
End Function
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Action()

'" TO DO: Place your action code here

Dim ctl, nRet, sErrStr
nRet = 0

lr.log_message " +++++++++++++++ Action(): Action Starting +++++++++++++++ "

lr.think_time 2

' // On Error Resume Next

' ShunraVEAPI.ShunraVEDController interface
Set ctrl = CreateObject("ShunraVEAPI.ShunraVEDController")
nRet = 0
nRet = ctrl.StopTest()
lr.log_message "The output of nRet is " + Cstr(nRet)

'if (nRet 0)
' sErrStr = ctrl.GetErrorString(nRet)
' lr.log_message "Error string is " + sErrStr
'end if

lr.log_message " +++++++++++++++ Action(): Action Ending +++++++++++++++ "
Action = lr.PASS

End Function
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Terminate()

'" TO DO: Place your termination code here

lr.log_message " +++++++++++++++ vuser_end(): Script Ending +++++++++++++++ "
Terminate = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Global Section :
'" List of global variables and objects.
'"
'" Visual Basic for Application References :
'" http://msdn.microsoft.com/vbasic/Default.asp
'"
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

'" Standard LoadRunner Objects.......................................
Dim lr As New LoadRunner.LrApi '" LR General API Object
Dim web As New LoadRunner.WebApi '" LR Web API Object
Dim objectHelper As New LoadRunnerVbs.ObjectFactory '" LR Object Factory Helper
Dim recordsetHelper As New LoadRunnerVbs.RecordSetHelper '" LR recordset Helper

'"Application's Global Objects/Variables............................
'
' Example: Dim myserver As Object
' Dim myint As Integer
' Dim mystringarray() As String


'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'" Script Description :
'"
'"
'" Script Author :
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Init() As Long

'" TO DO: Place your initialization code here

Init = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Action() As Long

'" TO DO: Place your action code here

Dim td
' td = CreateObject("TDApiOle80.TDConnection")
Set td = objectHelper.CreateObject("TDApiOle80.TDConnection.1")
td.InitConnectionEx("http://almdev/qcbin")
'Note: For Quality Center, connect by using the URL below:
'td.InitConnectionEx "http://:port/qcbin"
lr.start_transaction "ALM_DefectsDownload_Login"
td.ConnectProjectEx "DEFAULT", "PM_AND_SRT", "ABCD", ABCD

lr.end_transaction "ALM_DefectsDownload_Login", lr.PASS

lr.output_message "Login successful"

Dim bugFactory As TDAPIOLELib.BugFactory
Dim bugList As TDAPIOLELib.List
dim bugListcount

'Get a list of all the defects.

set bugFactory = td.BugFactory
set bugList = bugFactory.NewList("")

bugListcount = bugList.count
lr.output_message "The total number of defects is " +Cstr(bugListcount)

' Export defects to excel sheet

Dim objExcel, strExcelPath, objSheet

strExcelPath = "c:\temp\Sample4.xls"

lr.output_message " The path of excel sheet is " +Cstr(strExcelPath)

lr.start_transaction "ALM_DefectsDownload_DefectsExport"

' Open specified spreadsheet and select the first worksheet.
Set objExcel = CreateObject("Excel.Application")
objExcel.WorkBooks.Open strExcelPath
Set objSheet = objExcel.ActiveWorkbook.Worksheets(1)

Dim Row
Row = 2
objSheet.Cells(1, 1).Value = "BG_BUG_ID"
objSheet.Cells(1, 2).Value = "Bug.Summary"
objSheet.Cells(1, 3).Value = "Bug.DetectedBy"
objSheet.Cells(1, 4).Value = "Bug.Priority"
objSheet.Cells(1, 5).Value = "Bug.Status"
objSheet.Cells(1, 6).Value = "Bug.AssignedTo"

'Iterate through all the defects.
For Each Bug In bugList
'Save a specified set of fields.
'lr.output_message "For Entered"
objSheet.Cells(Row, 1).Value = Bug.Field("BG_BUG_ID")
objSheet.Cells(Row, 2).Value = Bug.Summary
objSheet.Cells(Row, 3).Value = Bug.DetectedBy
objSheet.Cells(Row, 4).Value = Bug.Priority
objSheet.Cells(Row, 5).Value = Bug.Status
objSheet.Cells(Row, 6).Value = Bug.AssignedTo

Row = Row + 1
Next

objExcel.ActiveWorkbook.Save
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
lr.end_transaction "ALM_DefectsDownload_DefectsExport", lr.PASS

Action = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Terminate() As Long

'" TO DO: Place your termination code here
Terminate = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'" Script Description :
'"
'"
'" Script Author :
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Init() As Long

'" TO DO: Place your initialization code here

Dim td
Dim tfact
Dim tlist
Dim Count_Of_Tests
'Count_Of_Tests = tlist.count
Dim Count_Of_Tests1
Dim tCoverageList

'Dim rand As New Random
'Dim rand Rnd

Dim index As Integer
Dim index1 As Integer
Dim max As Integer
Dim min As Integer
' Dim rnd = New Random()
Dim max1 As Integer
Dim min1 As Integer

Dim RequirementType
Dim RequirementName

Dim IterationNumber1 As Integer
Dim TestScriptName
Dim TestCoverageStatus
Dim TestCoverageDetails
Dim arr()
Dim ExecutionNumber
Dim done As Boolean
Dim k As Integer

Dim IterationNumber As Integer

'dim ExStrg.ClientPath as String
Init = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Action() As Long

'" TO DO: Place your action code here

Dim td

'td = CreateObject("TDApiOle80.TDConnection")
Set td = objectHelper.CreateObject("TDApiOle80.TDConnection.1")
td.InitConnectionEx("http://almdev/qcbin")
lr.start_transaction "ALM_AttachmentDownload_Login"
td.ConnectProjectEx "DEFAULT", "PM_AND_SRT", "ABCD", ABCD
lr.output_message "Login successful"

lr.end_transaction "ALM_AttachmentDownload_Login", lr.PASS

Dim tsfact As TDAPIOLELib.TestSetFactory
Dim tslist As TDAPIOLELib.List

Dim tfact
Dim tlist
Set tCoverageList = Nothing
'Set tfact = td.TestFactory
'Set tlist = tfact.NewList("")
'Set Count_Of_Tests = tlist.count

'************************ACCESS ALL THE TEST SETS ******************************************************************** '
set tsfact = td.TestSetFactory
set tslist = tsfact.NewList("")
'************************GET THE COUNT OF TEST SETS ******************************************************************
Dim Count_Of_TestSets
Count_Of_TestSets = tslist.Count
lr.output_message "Count of Test Sets" + Cstr(Count_Of_TestSets)

'************************GET A RANDOM TEST SET INDEX ***************************************************************

'Create temporaty list with all test set having attachment
Dim Temporary_List As TDAPIOLELib.List
dim Temporary_ListCnt as Integer
set Temporary_List = New TDAPIOLELib.List
For Each tempTestSet In tslist
If tempTestSet.HasAttachment Then
Temporary_List.Add(tempTestSet)
End If

Next

Temporary_ListCnt = Temporary_List.Count
lr.output_message "Count of Temporary Test Sets" + Cstr(Temporary_ListCnt)

Dim index As Integer
Dim max As Integer
Dim min As Integer

'Get the Random index number test set with attachment
min = 1
max = Temporary_ListCnt

If Temporary_ListCnt > 0 Then
index = Int((max - min + 1) * Rnd + min)
lr.output_message "Random Test Set(with attachment) Index:" + CStr(index)
End If

While index = 0

If Temporary_ListCnt > 0 Then
index = Int((max - min + 1) * Rnd + min)
lr.output_message "Random Test Set(with attachment) Index:" + CStr(index)
End If
Wend
'************************GET THE TEST SET PROPERTIES ASSOCIATED WITH THIS INDEX ***********************************
Dim TestSetID1 As Integer
Dim TestSetName1 As String
Dim IterationNumber2 As Integer
'Dim done = False
Dim AttachmentID
Dim AttachmentName
'Dim rand3 As New Random

lr.output_message "DISPLAYING TEST SET PROPERTIES ASSOCIATED WITH THE INDEX"

Dim testSet As TDAPIOLELib.TestSet

set testSet = Temporary_List.Item(index)

TestSetID1 = testSet.ID
TestSetName1 = testSet.Name
lr.output_message "TestSetID1 :" +Cstr(TestSetID1)
lr.output_message "TestSetName1 :" +Cstr(TestSetName1)

dim Attachmentcount as Integer

Dim afact As TDAPIOLELib.AttachmentFactory
Dim alist As TDAPIOLELib.List

set afact = testSet.Attachments()
set alist = afact.NewList("")
Attachmentscount = alist.Count
lr.output_message "Count of Attachments for the test set : " + Cstr(Attachmentscount)

Dim index1 As Integer

Dim max1 As Integer
Dim min1 As Integer
min1 = 1
max1 = Attachmentscount

index1 = Int((max1 - min1 + 1) * Rnd + min1)
lr.output_message "Random Attachment Index:" +Cstr(index1)

'***********************GET THE ATTACHMENT PROPERTIES ASSOCIATED WITH THIS INDEX **************************************

Dim attachment As TDAPIOLELib.Attachment

set attachment = alist.Item(index1)
AttachmentID = attachment.ID
AttachmentName = attachment.Name

lr.output_message "AttachmentID :" +Cstr(AttachmentID)
lr.output_message "AttachmentName :" +Cstr(AttachmentName)

Dim theAttach
Dim ExStrg

set theAttach = afact.Item(AttachmentID)

If theAttach Is Nothing Then
lr.output_message "Attachment is not found"
Exit Function
End If

If Not (theAttach.FileSize > 0) Then
lr.output_message "Attachment" + AttachmentName + "has zero size."
Exit Function
End If

' Get the attachment extended storage object.
set ExStrg = theAttach.AttachmentStorage

'Folder C does not exist. The Load call will create it.
'set ExStrg.ClientPath = "C:\temp\C"

'ExStrg.ClientPath

lr.start_transaction "ALM_AttachmentDownload_DownloadAttachment"

theAttach.AttachmentStorage.ClientPath = "C:\temp\C"
ExStrg.Load AttachmentName,True
lr.output_message "Download Complete"
lr.end_transaction "ALM_AttachmentDownload_DownloadAttachment", lr.PASS

Action = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Terminate() As Long

'" TO DO: Place your termination code here

Terminate = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'" Script Description :
'"
'"
'" Script Author :
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Init() As Long

'" TO DO: Place your initialization code here

Dim td
Dim tfact
Dim tlist
Dim Count_Of_Tests
'Count_Of_Tests = tlist.count
Dim Count_Of_Tests1
Dim tCoverageList

'Dim rand As New Random
'Dim rand Rnd

Dim index As Integer
Dim index1 As Integer
Dim max As Integer
Dim min As Integer
' Dim rnd = New Random()
Dim max1 As Integer
Dim min1 As Integer

Dim RequirementType
Dim RequirementName

Dim IterationNumber1 As Integer
Dim TestScriptName
Dim TestCoverageStatus
Dim TestCoverageDetails
Dim arr()
Dim ExecutionNumber
Dim done As Boolean
Dim k As Integer

Init = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Action() As Long

'" TO DO: Place your action code here

Dim td
' td = CreateObject("TDApiOle80.TDConnection")
Set td = objectHelper.CreateObject("TDApiOle80.TDConnection.1")
td.InitConnectionEx("http://almdev/qcbin")
'Note: For Quality Center, connect by using the URL below:
'td.InitConnectionEx "http://:port/qcbin"
'td.ConnectProjectEx("DEFAULT", "PM_AND_SRT", "ABCD", "ABCD_Password")
td.ConnectProjectEx "DEFAULT", "PM_AND_SRT", "srt", lr.decrypt("5279dc0d9b7f1348a39c007d5e15")
lr.output_message "Connection successful"

Dim tfact
Dim tlist
Set tCoverageList = Nothing
'Set tfact = td.TestFactory
'Set tlist = tfact.NewList("")
'Set Count_Of_Tests = tlist.count

'************************ACCESS ALL THE TEST CASES ********************************************************************

Set tfact = td.TestFactory
Set tlist = tfact.NewList("")

'************************GET THE COUNT OF TEST CASES ******************************************************************

Count_Of_Tests = tlist.count
'Count_Of_Tests1 = Count_Of_Tests.ToString
'Dim Set Count_Of_Tests1= Count_Of_Tests.ToString
'Count_Of_Tests.ConvertToString(Count_Of_Tests)
'Count_Of_Tests.CStr("")
lr.output_message "Count of Test Scripts" + CStr(Count_Of_Tests)

'************************GET A RANDOM TEST SCRIPT INDEX ***************************************************************

Dim index As Integer
'dim rand as
'
max = tlist.count
min =0
if tlist.count > 0 Then
'index = Rnd(0,tlist.count)
index = Int((max - min + 1) * Rnd + min)
'Set max= tlist.count
'min=1
'Randomize
'index = Int((max-min+1)*Rnd+min)
'Choose a random index.
'index = rand.Next(0, tlist.Count)
'index = rand() % tlist.Count
'Get the item at that index.
' Console.WriteLine("Random Test Script Index:" + index.ToString())
lr.output_message "Random Test Script Index:" + CStr(index)
End If

While index = 0

If tlist.Count > 0 Then
'Choose a random index.
'index = rand.Next(0, tlist.Count)
index = Int((max - min + 1) * Rnd + min)
'Get the item at that index.
'Console.WriteLine("Random Test Script Index:" + index.ToString())
lr.output_message "Random Test Script Index if test script index is 0 :" + CStr(index)
End If
Wend

Dim rfact
Dim rlist

'************************ACCESS ALL THE REQUIREMENTS ******************************************************************

Set rfact = td.ReqFactory
Set rlist = rfact.NewList("")

'************************GET THE COUNT OF REQUIREMENTS*****************************************************************

Dim Count_Of_Requirements
Count_Of_Requirements = rlist.count
' Console.WriteLine("Count of Requirements:" + Count_Of_Requirements.ToString)
lr.output_message "Count of Requirements:" + CStr(Count_Of_Requirements)

'************************GET A RANDOM REQUIREMENT ID ******************************************************************

Set RequirementType = Nothing
Dim RequirementID As Integer
Set RequirementName = Nothing

Do
' Dim rand1 As New Random
Dim index1 As Integer
'Dim item As Object
'Display the items in random order.
max1 = rlist.count
min1 =0

If rlist.Count > 0 Then
'Choose a random index.
'index1 = rand1.Next(0, rlist.Count)
index1 = Int((max1 - min1 + 1) * Rnd + min1)
'Get the item at that index.
' Console.WriteLine("Index of the Requirement" + index1.ToString())
lr.output_message "Index of the Requirement:" + CStr(Count_Of_Requirements)
End If

While index1 = 0

If rlist.Count > 0 Then
'Choose a random index.
'index1 = rand1.Next(0, rlist.Count)
index1 = Int((max1 - min1 + 1) * Rnd + min1)
'Get the item at that index.
'Console.WriteLine(index1.ToString())
lr.output_message "Random Requirement ID if index is 0 :" + CStr(index1)
End If

Wend

'************************GET THE REQUIREMENT PROPERTIES ASSOCIATED WITH THIS INDEX ***********************************

Dim IterationNumber1 As Integer

IterationNumber1 =0

For Each Req In rlist
'MsgBox(Test.Name)
'Console.WriteLine(Test.Name)
If IterationNumber1 = index1 Then
RequirementID = Req.ID
RequirementName = Req.Name
RequirementType = Req.TypeId
'Req.AddCoverage(TestScriptID, -4)
'done = True
Exit For
End If
IterationNumber1 =IterationNumber1 + 1
Next

Loop While StrComp(RequirementType, "Folder") = 0

'Console.WriteLine("Requirement ID:" + RequirementID.ToString())
'Console.WriteLine("Requirement Name:" + RequirementName)
'Console.WriteLine("Requirement Type:" + RequirementType)
lr.output_message "Requirement ID:" + CStr(RequirementID)
lr.output_message "Requirement Name:" + RequirementName
lr.output_message "Requirement Type:" + RequirementType

'************************GET THE TEST SCRIPT PROPERTIES ASSOCIATED WITH THIS INDEX ***********************************

Dim TestScriptID As Integer
Set TestScriptName = Nothing
Set TestCoverageStatus = Nothing
Set TestCoverageDetails = Nothing
Set arr = Nothing

Dim IterationNumber As Integer

'IterationNumber = 0
For Each Test In tlist
'MsgBox(Test.Name)
'Console.WriteLine(Test.Name)
If IterationNumber = index Then
TestScriptID = Test.ID
TestScriptName = Test.Name
TestCoverageStatus = Test.HasCoverage()
tCoverageList = Test.GetCoverList()
'************** IF COVERAGE ALREADY EXITS B/N TEST AND REQ SKIP ; ELSE PERFORM THE COVERAGE ******************************
' Dim m As Integer = 1

done = False
if StrComp(done, "False") = 0 Then

'Console.WriteLine("OK Performing the requirement coverage NOW...")

lr.output_message "OK Performing the requirement coverage NOW..."

ExecutionNumber = 0
'Console.WriteLine("Test Script ID:" + TestScriptID.ToString())
lr.output_message "Test Script ID:" + CStr(TestScriptID)

'Console.WriteLine("Test Script Name:" + TestScriptName)
'lr.output_message "Test Script Name:" + TestScriptName
' Console.WriteLine("Test Coverage Status:" + TestCoverageStatus.ToString)
'lr.output_message "Test Coverage Status:" + CStr(TestCoverageStatus)

Test.CoverRequirement rfact.Item(RequirementID), -4, True

' Console.WriteLine("Coverage Added...Check Whether this Coverage got added in the Front End...Hit Enter to Continue")
' Console.ReadLine()
' lr.output_message "Coverage Added...Check Whether this Coverage got added in the Front End...Hit Enter to Continue"

Test.RemoveCoverage(RequirementID)
' Console.WriteLine("Coverage Removed...")

'lr.output_message "Coverage Removed..."

ExecutionNumber = ExecutionNumber + 1
'Console.WriteLine("Requirement Coverage Logic is executed ::" + ExecutionNumber.ToString + "Hit Enter to Continue...")
'lr.output_message "Requirement Coverage Logic is executed ::" + CStr(ExecutionNumber) + "Hit Enter to Continue..."

End If

exit For

IterationNumber = IterationNumber+ 1

End if

Next

'***********************IF TEST HAS REQ COVERAGE; DISPLAY THE REQUIREMENTS THAT ARE COVERED***************************

for Each Test In tlist

if IterationNumber = index Then

tCoverageList = Test.GetCoverList()
k=1
For Each Req In tCoverageList
arr(k) = Req.ID
'Console.WriteLine("Req # " + k + "::" + Req.ID.ToString)
lr.output_message "Req #" + k + "::" + CStr(Req.ID)
'k += 1
k=k+1
Next
end if
Next

Set tlist = Nothing
Set tfact = Nothing

Set td = Nothing

Action = lr.PASS
End Function

'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'" Script Title :
'"
'" Script Date :
'"'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Public Function Terminate() As Long

'" TO DO: Place your termination code here

Terminate = lr.PASS
End Function