QTP/UFT: QC/ALM Open Test Architecture(OTA)



'ALL FUNCTIONs ARE RELATED WITH ALM 
'Created by : Miah, Create date 08/04/2014
'###############################################
'#CONNECT TO ALM(QC) WITH USER access information
Public Function qcConnect()
	'Environment.LoadFromFile "D:\QCTOEXCEL\config.xml"
	serverNm = Environment.Value("Server")
	domainNm = Environment.Value("Domain")
	projectNm = Environment.Value("Project")
	userName = Environment.Value("Username")
	userPwd = Environment.Value("Password")
	'Create the QTP Application object to connect
	Set qcConnect = CreateObject("TDApiOle80.TDConnection")
	qcConnect.InitConnectionEx(serverNm)

	if(qcConnect.LoggedIn = false) then	
		qcConnect.Login userName, userPwd
		qcConnect.Connect  domainNm, projectNm
	End If
	
End Function

'#CLOSE ALM CONNECTION and LOGOUT
Public Function qcDisConnect(qcCon)
	qcCon.Disconnect()
	qcCon.Logout()
	qcCon.ReleaseConnection()	
End Function

'#GET ALL TEST DATA FROM 'Parameters' TAB
Public Function getParametersData(objPerm)
	Dim strParam()
	Set paramSteps = objPerm.TestParameterFactory
	Set paramAllSteps = paramSteps.NewList("")
	val = 0
	For each paramSteps in paramAllSteps
		val =val + 1
		ReDim Preserve strParam(val)
		strParaName= paramSteps.Field("TP_NAME")'Parameter Name
		strParaValu= paramSteps.Field("TP_DEFAULT_VALUE")'Default Value
		strParam(val)= strParaName & "=" & strReplace(strParaValu)
		'MsgBox strReplace(strParaValu)
	Next
	getParametersData = strParam 'Return
End Function

'#GET ALL TEST DATA FROM 'Test Configurations' TAB BY TEST ID
Public Function getTestConfigurationsData(qcCon, testID)
	Dim strParamData()
	Set cmd = qcCon.Command
	cmd.CommandText = "SELECT * FROM STEP_PARAMS WHERE SP_OWNER_ID = (select TSC_ID from TEST_CONFIGS where TSC_TEST_ID ='" & testID & "')"
	Set rslt = cmd.Execute()
	val = 0
	'When Test data not fount in 'Test Configurations'
	ReDim Preserve strParamData(val)
	strParamData(val) = "Executed=No Run"
	
	While Not rslt.EOR
		val =val + 1
		ReDim Preserve strParamData(val)
		'Msgbox rslt("SP_PARAM_NAME")
		strParamData(val) = rslt("SP_PARAM_NAME") & "=" & strReplace(rslt("SP_PARAM_ACTUAL_VALUE"))
		rslt.Next()
	Wend
	
	If val > 0 Then
		'Initially set it to pass for now, on the fly it may change to 'Failed' any where in the action
		Environment.Value("TestStatus") = "Passed"
	Else
		Environment.Value("TestStatus") = "No Run"
	End If
	
	getTestConfigurationsData =strParamData 'Return
End Function

'#CREATE TEST SET in TEST LAB
Public Function createTestSet(qcCon, TreManager, tpFolderPath)
	tsCreated = False
	tsFolder = Environment.Value("TestLabFolder")
	tsName = Environment.Value("TestSetName")
	tsFolderPath = Environment.Value("TestSetPath")
	'Create a Directory and Test Set in Test Lab the add test cases in it
	'Set QCTreeManager = qcConnect.treeManager
	Set TestNode = TreManager.NodebyPath(tpFolderPath)
	Set TestFact = TestNode.TestFactory
	Set TestsList = TestFact.NewList("")
	On Error Resume Next 'because tsFolderPath not found then move to next

	Set labTreeMgr = qcCon.TestSetTreeManager
	Set labFolder = labTreeMgr.NodeByPath(tsFolderPath)
	'IF TEST SET DIRECTORY NOT FOUND THEN CREATE ONE
	If labFolder Is Nothing Then
		Set labTreeRoot = labTreeMgr.Root
    	Set labFolder = labTreeRoot.AddNode(tsFolder)
    	labTreeRoot.Post
   	 	tsCreated = True
	Else
    	tsCreated = False
	End If
	'CREATE A TEST SET Regression if not exist
	Set testSetF = labFolder.TestSetFactory
	Set aFilter = testSetF.Filter
	'Get test set name, it id given by the user example Regresstion
	aFilter.Filter("CY_CYCLE") = tsName 
	Set lst = testSetF.NewList(aFilter.Text)
	If lst.Count = 0 Then
		Set TstSet = testSetF.AddItem(Null)
    	TstSet.Field("CY_CYCLE") = tsName'tsName = "Regression" nedd to be pass
    	TstSet.Post
	Else
    	Set TstSet = lst.Item(1)
	End If 
End Function

'#ADD TEST in TEST SET for Run STATUS
Public Function addTestInTestSet(qcCon, tpFolderPath, TreManager, TestName)
	tsCreated = False
	tsFolder = Environment.Value("TestLabFolder")
	tsName = Environment.Value("TestSetName")
	tsFolderPath = Environment.Value("TestSetPath")
	
	'Create a Directory and Test Set in Test Lab the add test cases in it
	Set TestNode = TreManager.NodebyPath(tpFolderPath)
	Set TestFact = TestNode.TestFactory
	Set TestsList = TestFact.NewList("")
	On Error Resume Next 'because tsFolderPath not found then move to next

	Set labTreeMgr = qcCon.TestSetTreeManager
	Set labFolder = labTreeMgr.NodeByPath(tsFolderPath)
	'IF TEST SET DIRECTORY NOT FOUND THEN CREATE ONE
	If labFolder Is Nothing Then
		Set labTreeRoot = labTreeMgr.Root
   	 Set labFolder = labTreeRoot.AddNode(tsFolder)
    	labTreeRoot.Post
    	tsCreated = True
	Else
    	tsCreated = False
	End If
	'CREATE A TEST SET Regression if not exist
	Set testSetF = labFolder.TestSetFactory
	Set aFilter = testSetF.Filter
	'Get test set name, it id given by the user example Regresstion
	aFilter.Filter("CY_CYCLE") = tsName 
	Set lst = testSetF.NewList(aFilter.Text)
	'MsgBox lst.Count
	If lst.Count = 0 Then
		Set TstSet = testSetF.AddItem(Null)
   		TstSet.Field("CY_CYCLE") = tsName'tsName = "Regression" nedd to be pass
    	TstSet.Post
	Else
    	Set TstSet = lst.Item(1)
	End If 

	'FIND TEST CASE ALREADY EXIST IN 
	Set tsTreeMgr = qcCon.TestSetTreeManager
	Set tsFolder = tsTreeMgr.NodeByPath(tsFolderPath) 'TEST PLAN
	Set tsList = tsFolder.FindTestSets(tsName) 'IN TEST LAB
	Set testset = tsList.Item(1)
	'MsgBox testSet.Name 'TEST SET NAME
	Set TSTestFactory = TstSet.TSTestFactory
	Set TSTestFact = testSet.TSTestFactory
	Set TestSetTestsList = TSTestFact.NewList("")
	''When Test case not exist at all in Test lab
	For Each tests In TestsList
		For each thetest In TestSetTestsList
			'MsgBox thetest.name
			tcFound = False
			If thetest.TestName = tests.Name Then
				tcFound = True
				Exit For
			End if
		Next

		If (tcFound = False) And (TestName = tests.Name) Then 'if test case not found then add one
			'If tests.Automated = "Yes" Then'Automated field for BCS project
			'If tests.Field("TS_USER_09")) = "Yes" Then 'Automated field for BCS project
			If tests.field("TS_TYPE") = "MANUAL" or tests.Field("TS_USER_09") = "Yes" Then
				TSTestFactory.AddItem (tests)
			End If
		End If
	Next
End Function

'#UPDATE TESTING STATUS WITH Passed, Failed, No Run OR Blocked
Public Function updateTestingStatus(qcCon, TestName)
	testStatus = Environment.Value("TestStatus")
	tsName = Environment.Value("TestSetName")
	tsFolderPath = Environment.Value("TestSetPath")
	'UPDATED EXISTING TEST STATUS
	Set tsTreeMgr = qcCon.TestSetTreeManager
	Set TestSetFolderPath=tsTreeMgr.NodeByPath(tsFolderPath)   
	set tSet = TestSetFolderPath.TestSetFactory.Filter
	'tSet.Filter("CY_CYCLE")=tsName 'Get test Set name
	'MsgBox tSet.Filter("CY_CYCLE")
	set tsl = tSet.NewList()
	If tsl.count > 0 Then
		For i=1 to tsl.count
			Set ts = tsl.Item(i)
			Set tsFilter = ts.TSTestFactory.Filter
			strFilter= Chr(34) & "*" & TestName & "*" & Chr(34)
			'MsgBox strFilter
			tsFilter.Filter("TS_NAME")=TestName
			Set tCase=tsFilter.NewList()

			If tCase.count > 0 Then
				For j=1 to tcase.count
					tCase(j).Field("TC_STATUS")=testStatus
					tCase(j).Post()
					tCase(j).Field("TC_TESTER_NAME")=Environment.Value("Username")
					tCase(j).Post()
				Next   ' End of test CASE loop
			'Else
				'MsgBox( "Test case " & TestName & " is not found! ")
			End If
		Next   'End of test SET loop
	'Else
		'MsgBox( "Test set " & tsName & " is not found ")
	End If
End Function

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s