Protected: QTP/UFT: QC/ALM PowerBuilder Click Button

This content is password protected. To view it please enter your password below:

Advertisements

QTP/UFT: Generate Alphanumeric and Random Number

”’## 3 digits Random idNumber and 7 digits Random serialNumber
    Dim start, ends
    start = 1
    ends = 19
    For m = start To ends
        idNumber = RandomNumber (111919)
        serialNumber = RandomNumber (11119991119999)
    Next

”## Generate Alphanumeric Number
Function generateAlphanumeric(StrLen)
Dim alpNumStr
Const MainStr= “0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ”
For i = 1 to StrLen
  alpNumStr=alpNumStr & Mid(MainStr,RandomNumber(1Len(MainStr)),1)
Next
generateAlphanumeric = alpNumStr
End Function
”## 3 digits Alphanumeric Number
serialNum = generateAlphanumeric(3)

QTP/UFT: Current Date Time Stamps and Julian-Date

”### Current Date Time Stamps
Dim currentDateTime, currentDate, currentTime, newDateYear
currentDateTime = Now
currentDate = Date
myDate = replace(currentDate,“/”,“-“)
myDay = Day(currentDate)
myMonth = Month(currentDate)
myYear = Year(currentDate)
myAbbMonth = MonthName(myMonth, true)
currentTime = Time
newDateYear = DateAdd(“yyyy”,3,currentDate)

” #### Use Date for currentDate or any date like “10/21/2011” #####
”cJulianDate = CalculateJulianDate(Date)
”msgbox cJulianDate
Function CalculateJulianDate(ByVal jDate)
    Dim jYear,jFirstDayOfYear,jDay,JulianDate
    ‘jDate = Date
    jYear = Year(jDate)
    jFirstDayOfYear = “01/01/”&jYear
    jDay = DateDiff(“d”Cdate(jFirstDayOfYear), Cdate(jDate)) + 1
    If Len(jDay)<3 Then
        jDayOnly = Right(“0” & jDay, 3)
        else
        jDayOnly = jDay
    End If
    JulianDate = (RIGHT(jYear,2))&jDayOnly
    CalculateJulianDate = JulianDate
End Function
” #### End Codify #####
 treeSelection = PbWindow(“w_Pb_frame”).PbWindow(“w_Pb_frame”).PbTreeView(“Pb_TreeView”).GetROProperty (“selection”)
serialNumber = trim(Right(treeSelection,5))  ”Last 5 digits from Right

”## If 3 digits Julian Date needed
cJulianDay = right(CalculateJulianDate(Date),3)

”## Add the All string number
addStrNumber = Code + cJulianDay + serialNumber

QTP/UFT: Input and Output Parameter

”##Create Test (Start) Parameter “myPin”
”##Create Action (Action1) Parameter “enterPinNumber”
”## Set the Parameter
Dim enterPinNumber
enterPinNumber = TestArgs(“myPin”)
‘msgbox enterPinNumber
”## Run Test with Test Parameter
PbWindow(“w_Pb_frame”).PbEdit(“Pb_edit”).SetSecure enterPinNumber

”## Run Action with Action Parameter
RunAction “openApp [open_Application]”, oneIteration, Parameter(“inputParameter”)

”## Create a Output Parameter “userIDNo”
”## Get the “idNum” Value at RunTime
idNum = trim(PbWindow(“w_Pb_frame”).PbWindow(“w_Pb_frame”).PbDataWindow(“dw_window”).GetCellData (11))
”## Set the Output Parameter Value
Parameter(“userIDNo”) = idNum

”## Select a Power Builder Cell that match from QTP/UFT Runtime Data Table
PbWindow(“w_Pb_frame”).PbWindow(“w_Pb_frame”).PbDataWindow(“dw_window”).SetCellData “#1”,“lastname”,DataTable.Value(“LastName”,addNewUser)
”Return Output Parameter “newUserLastName”
Parameter(“newUserLastName”) = DataTable.Value(“LastName”,addNewUser)

QTP\UFT: Action template

Action template in UFT

1.  Go to your UFT installation folder

2.  Go to dat folder and find ActionTemplate.mst file

UFT dat folder

3.  Open the ActionTemplate.mst file with Notepad

4.  Copy Paste below text and save it

Rem— Note: This is a Action Script for Power Builder App (Miah Borhanuddin – Jun, 17, 2014)

”’###########################################################
”Project Name: –    Application project Name
”Purpose: – 
”Author: –        Miah
”Date Created: – 4/9/2015
”Action Name: Action1
”Action Description:
”Resources:
”Change History: –
”***********************************************************
”’###########################################################

5.  Create a New GUI Test from UFT you will see following

UFT Action Template

 

QTP/UFT: Excel Data Import/Export

QTP/UFT: Excel Data Import/Export at Run-time DataTable
””##########################################################

Dim WshShell
‘Dim WshSysEnv
Set WshShell = CreateObject (“WScript.Shell”)

OSType = Environment.Value(“OS”)
OsXp = “Microsoft Windows XP”
XpPath = “C:\Documents and Settings\”& Environment.Value(“UserName”) &“\My Documents\”
‘Win7Path = “C:\Users\”& Environment.Value(“UserName”) &”\Documents\”  ”User Profile
Win7Path = WshShell.ExpandEnvironmentStrings (“%USERPROFILE%”) &“\Documents\” ”Current loged on Profile

”’Import data from Local or from QC at RunTime –TableName = SheetName–
Function addQCdata(FileName,TableName)
If FilePath = “” Then ”’If Local Data path not Define
ExcelPath=(“[QualityCenter\Resources] Resources\QTP Resources\AppDAT\”& FileName)
Else ”’If Local Data path is Defined
ExcelPath=(FilePath & FileName &“.xls”)
End If
SystemUtil.CloseProcessByName(“Excel.exe”)
DataTable.AddSheet (TableName)
DataTable.ImportSheet ExcelPath, TableName, TableName
Set ExcelPath = nothing
End Function

”’Export RunTime Data to Documents Folder –TableName = SheetName–
”’Save Runtime Data in Documents Folder as a Excel format
Function SaveReport(FileName,TableName)
OSType = Environment.Value(“OS”)
UserID = Environment.Value(“UserName”)
OsXp = “Microsoft Windows XP”

If OSType = OsXp Then
DataTable.ExportSheet XpPath&FileName&“.xls”, TableName
Else
DataTable.ExportSheet Win7Path&FileName&“.xls”, TableName
End If
End Function

Rem — ############## OR ##############

”’Export RunTime Data to Documents Folder –TableName = SheetName–
Function exportData(FileName,TableName)
OSType = Environment.Value(“OS”)
UserID = Environment.Value(“UserName”)
OsXp = “Microsoft Windows XP”

If OSType = OsXp Then
DataTable.ExportSheet “C:\Documents and Settings\”& UserID &“\My Documents\”&FileName&“.xls”, TableName
Else
DataTable.ExportSheet “C:\Users\”& UserID &“\Documents\”&FileName&“.xls”, TableName
End If
Set OSType = nothing
Set UserID = nothing
Set OsXp = nothing
End Function

”’To use this Function You have to Use a SetUp.xls File  –TableName = SheetName–
”’Download the SetUp.xls File From Quality Center (ALM)
”’Define the Path in the DataPath Sheet
”’Example:
”’ScriptName : 02-UserLogin
”’LocalDataFilePath: C:\Users\userid\Documents\AppData\Automation_Data\
”’Move the ” SetUp.xls ” file to My Documents for Xp or Documents for Documents
Function AddALMData(FileName,TableName)
On Error Resume Next
SystemUtil.CloseProcessByName(“Excel.exe”)
DataTable.AddSheet (“DataPath”)
If OSType = OsXp Then
DataTable.ImportSheet XpPath&“SetUp.xls” ,“DataPath”,“DataPath”
Else
DataTable.ImportSheet Win7Path&“SetUp.xls” ,“DataPath”,“DataPath”
End If
pathRows=DataTable.GetSheet(“DataPath”).GetRowCount
For p=1 to pathRows
DataTable.GetSheet(“DataPath”).SetCurrentRow(p)
If DataTable.Value(“ScriptName”,“DataPath”)=Environment.Value(“TestName”Then
If DataTable.Value(“LocalDataFilePath”,“DataPath”) > “0” Then
FilePath= DataTable.Value(“LocalDataFilePath”,“DataPath”)
‘msgbox FilePath
else
Reporter.ReportEvent micDone, “DataFile”“App Data File is not Setup from Local”
End If
End If
Next

If FilePath = “” Then
ExcelPath=(“[QualityCenter\Resources] Resources\QTP Resources\AppDATA\”& FileName)
Reporter.ReportEvent micDone, “DataFile”“App Data File is Setup from QC”
Else
ExcelPath=(FilePath & FileName &“.xls”)
Reporter.ReportEvent micDone, “DataFile”“App Data File is Setup from Local”
End If
DataTable.AddSheet (TableName)
DataTable.ImportSheet ExcelPath, TableName, TableName
‘   DataTable.ImportSheet ExcelPath, TableName, Environment.Value(“ActionName”)     ”## You can edit script to make it Datatable Per Action
Set FilePath = nothing
Set ExcelPath = nothing
End Function

”’ How to Use It, Call it in your Script, FileName, SheetName
Call AddALMData(“AppTestDataCNN”,“UserLogon”)

rowCnt = DataTable.GetSheet(“UserLogon”).GetRowCount
For i=1 To rowCnt
DataTable.GetSheet(“UserLogon”).SetCurrentRow(i)
”’Your Condition
”’Your Condition
”’Your Condition
Next

 

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