These functions can be directly executed from QTP but make sure QC is connected through QTP.
Function to Remove User
Public Function RemoveUser(strUser)
'Declare local variables
Dim objCustUsers 'As Users object
On Error Resume Next
Set objCustUsers = QCUtil.QCConnection.Customization.Users
objCustUsers.RemoveUser(strUser)
QCUtil.QCConnection.Customization.commit
If Err.Number <> 0 Then
Reporter.ReportEvent micFail,"Remove User",Err.Description
Else
Reporter.ReportEvent micPass,"Remove User","The User " & strUser & " removed successfully"
End If
On Error Goto 0
'Release the object
Set objCustUsers = Nothing
End Function
Function to Add User:
Public Function AddUser(strUser, strUserGroup)
Dim objCust 'As Customization object
Dim objCustUsers 'As Users object
Set objCust = QCUtil.QCConnection.Customization
objCust.Load
On Error Resume Next
Set objCustUsers = objCust.Users
objCustUsers.AddUser strUser
If Err.Number <> 0 Then
Print Err.Description
On Error GoTo 0
ExitTestIteration
End If
Set objUsersGroup = objCust.UsersGroups
Set objCustGrp = objUsersGroup.Group(strUserGroup)
objCustGrp.AddUser(strUser)
objCust.commit
If Err.Number <> 0 Then
Reporter.ReportEvent micFail,"Adding User '" & strUser & "'",Err.Description
Else
Reporter.ReportEvent micPass,"Adding User",strUser & " Added successfully"
End If
On Error GoTo 0
Set objCust = Nothing
Set objCustUsers = Nothing
Set objUsersGroup = Nothing
Set objCustGrp = Nothing
End Function
Function to Get the number of users available on a particular QC Project:
Public Function GetUsersCount() 'Return as Integer
'Declare local variables
Dim objCustUsers 'As Users object
Dim objUserList
On Error Resume Next
Set objCustUsers = QCUtil.QCConnection.Customization.Users
Set objUserList = objCustUsers.Users
intUsersCount = objUserList.count
If Err.Number <> 0 Then
Reporter.ReportEvent micFail,"Get Users count",Err.Description
intUsersCount = -1
End If
On Error Goto 0
'For each USR in objUserList
' Print USR.name
'Next
Set objCustUsers = Nothing
Set objUserList = Nothing
GetUsersCount = intUsersCount
End Function
Thanks a lot for the nice tips.
ReplyDeleteHadoop training
ReplyDeleteHi
I read this post two times.
I like it so much, please try to keep posting.
Let me introduce other material that may be good for our community.
Hadoop training