python连接ALM
VBS腳本:
Public Function makeConnection(ByVal qcHostName$, qcDomain$, qcProject$, _
qcUser$, qcPassword$, Optional qcPort) As Boolean
'------------------------------------------------------------------------
' This routine makes the connection to the gobal TDConnection object
' (declared at the project level as Global tdc as TDConnection)
' and connects the user to the specified project.
'-----------------------------------------------------------------------
Dim qcServer As String
Const fName = "makeConnection" 'For error message
On Error GoTo makeConnectionErr
errmsg = ""
' Construct server argument using format:
' "http://server:port/qcbin"
qcServer = "http://" & qcHostName
If Not (IsMissing(qcPort)) Then
If Len(qcPort) > 0 Then qcServer = qcServer & ":" & qcPort
End If
qcServer = qcServer & "/qcbin"
' Check status (for demonstration purposes only).
' MsgBox tdc.LoggedIn 'Error: OTA Server is not connected
' MsgBox tdc.Connected 'False
' MsgBox tdc.ServerName 'Blank string
' Create the connection.
errmsg = "Failed to create TDConnection"
If (tdc Is Nothing) Then Set tdc = New TDConnection
If (tdc Is Nothing) Then GoTo makeConnectionErr
errmsg = ""
' Check status
' On Error Resume Next
' Debug.Print "Initial Status: "
' Debug.Print "LoggedIn", """" & tdc.LoggedIn & """"
' Debug.Print "LoggedIn Error", err.Description
' Debug.Print "Connected", """" & tdc.Connected & """"
' Debug.Print "ServerName", """" & tdc.ServerName & """"
' Debug.Print "ProjectName", """" & tdc.ProjectName & """"
' Debug.Print "ProjectName Error", err.Description
' Debug.Print "ProjectConnected", """" & tdc.ProjectConnected & """"
' Debug.Print "ProjectConnected Error", err.Description
' Debug.Print
' On Error GoTo makeConnectionErr
'
' Initial Status:
' LoggedIn Error OTA server is not connected.
' Connected "False"
' ServerName ""
' ProjectName Error OTA server is not connected.
' ProjectConnected Error OTA server is not connected.
tdc.InitConnectionEx qcServer
' Check status.
' On Error Resume Next
' Debug.Print "After InitConnectionEx: "
' Debug.Print "LoggedIn", """" & tdc.LoggedIn & """"
' Debug.Print "Connected", """" & tdc.Connected & """"
' Debug.Print "ServerName", """" & tdc.ServerName & """"
' Debug.Print "ProjectName", """" & tdc.ProjectName & """"
' Debug.Print "ProjectConnected", """" & tdc.ProjectConnected & """"
' Debug.Print
' On Error GoTo makeConnectionErr
''
'' After InitConnectionEx:
' LoggedIn "False"
' Connected "True"
' ServerName "http://server06/qcbin/wcomsrv.dll"
' ProjectName ""
' ProjectConnected "False"
' Log on to server.
tdc.Login qcUser, qcPassword
' Check status.
' Debug.Print "After Login: "
' Debug.Print "LoggedIn", """" & tdc.LoggedIn & """"
' Debug.Print "Connected", """" & tdc.Connected & """"
' Debug.Print "ServerName", """" & tdc.ServerName & """"
' Debug.Print "ProjectName", """" & tdc.ProjectName & """"
' Debug.Print "ProjectConnected", """" & tdc.ProjectConnected & """"
' Debug.Print
' After Login:
' LoggedIn "True"
' Connected "True"
' ServerName "http://server06/qcbin/wcomsrv.dll"
' ProjectName ""
' ProjectConnected "False"
' Connect to the project and user.
tdc.Connect qcDomain, qcProject
' Exit status.
' Debug.Print "After Connect: "
' Debug.Print "LoggedIn", """" & tdc.LoggedIn & """"
' Debug.Print "Connected", """" & tdc.Connected & """"
' Debug.Print "ServerName", """" & tdc.ServerName & """"
' Debug.Print "ProjectName", """" & tdc.ProjectName & """"
' Debug.Print "ProjectConnected", """" & tdc.ProjectConnected & """"
' Debug.Print
'
' After Connect:
' LoggedIn "True"
' Connected "True"
' ServerName "http://server06/qcbin/wcomsrv.dll"
' ProjectName "ota_doc"
' ProjectConnected "True"
makeConnection = True
Exit Function
makeConnectionErr:
makeConnection = False
ErrHandler err, fName, err.Description & vbCrLf & errmsg
End Function
Python腳本:
? ? def makeConnect(self):
? ? ? ? from win32com.client import Dispatch
? ? ? ? tdc = Dispatch("TDApiOle80.TDConnection") ? ?
? ? ? ? tdc.InitConnection(self.info['qcServer']) ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? #ALM服務器名,如:http://192.168.1.10:8080/qcbin
? ? ? ? tdc.Login(self.info['qcUser'],self.info['qcPassword']) ? ? ? ? ?#用戶名,密碼
? ? ? ? tdc.Connect(self.info['qcDomain'],self.info['qcProject']) ? ?#域,項目
? ? ? ? print tdc.Connected ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?#如果已連接,則為True,還有其它屬性,請參考VBS腳本
? ? ? ? return tdc
總結
以上是生活随笔為你收集整理的python连接ALM的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python之变量类型
- 下一篇: Python怎么识别文字?正确的方法详解