2014-11-24 53 views

回答

2

VBScript中的以下功能可以檢查當前測試是否在其對象存儲庫中具有特定名稱的對象。

Function CheckIfObjectPresentInOR(ByVal LogicalName) 
    Set ObjectRepositoryUtil = CreateObject("Mercury.ObjectRepositoryUtil") 
    ObjectRepositoryUtil.Load "<Path of the Object Repository>" 
    Set TOCOllection = ObjectRepositoryUtil.GetAllObjects 
    booFunctionStatus = FALSE 
    For i = 0 To TOCollection.Count - 1 
      If ObjectRepositoryUtil.GetLogicalName(TOCOllection.Item(i)) = LogicalName Then 
        booFunctionStatus = TRUE 
        Exit For 
      End If 
    Next 
    Set ObjectRepositoryUtil = Nothing 
    Set TOCOllection = Nothing 
    CheckIfObjectPresentInOR = booFunctionStatus 
End Function 

編輯:

Function CheckIfObjectPresentInOR 
    Set ObjectRepositoryUtil = CreateObject("Mercury.ObjectRepositoryUtil") 
    ObjectRepositoryUtil.Load "<Path of the Object Repository>" 
    booFunctionStatus = FALSE 
    Set TOCOllection = ObjectRepositoryUtil.GetAllObjects 
    If TOCOllection.Count > 0 Then 
     booFunctionStatus = TRUE 
    End If 
    Set ObjectRepositoryUtil = Nothing 
    Set TOCOllection = Nothing 
    CheckIfObjectPresentInOR = booFunctionStatus 
End Function 
+0

此代碼將工作,但我的要求略有不同,用戶不知道Object.I的名字的意思是,我只是想知道是否有本地對象內的任何對象repository.Just希望得到布爾結果「true」或「false」。條件是我不知道測試用例的「Local Repository」,我不想手動查看它,我想通過我的代碼檢查它。有什麼辦法可以嗎? – 2014-11-25 04:57:30

+0

檢查編輯。如果任何對象存在於本地對象存儲庫中,它就會給出。本地對象庫的路徑是\ \ \ objectrepository.bdp – vins 2014-11-25 16:07:52

+0

我試圖使用這段代碼,但它顯示'一般錯誤'在行當我給本地對象庫的路徑。你可以告訴什麼是錯的?名稱本地存儲庫的正確性? – 2014-11-26 12:29:11

相關問題