QTP/UFT: REMOVE QC/ALM HTML STRING FROM ORIGINAL STRING


'UTILITY.QFL
'REMOVE QC/ALM HTML STRING FROM ORIGINAL STRING
'Created by : Miah, Create date 05/24/2013
'strFul = Origional string
'strRemov1 = Any unwanded string first time will remove
'strRemov2 = Any unwanded string second time will remove
Public Function strReplace(strFul,strRmov1,StrRmov2)
	dCot = """
	strReplace =Replace(strFul, strRmov1, "")
	strReplace =Replace(strReplace, strRmov2, "")
	strReplace =Replace(strReplace, dCot, "'")
End Function

'FIND LAST FOLDER NAME FROM TEST PLAN DIRECTORY
'Created by : Miah, Create date 05/28/2013
Public Function findFoldNm(fulPath)
	spltStr=Split(fulPath,"\")
	cnt = uBound(spltStr) + 1
	'MsgBox cnt
	itr =0
	for each x in spltStr
		itr = itr + 1
		if cnt = itr Then
			findFoldNm = x
		End If
	next
End Function

'Get KEY and VALUE IN ARRY 
'input keyValuArray = (Test1=1, Test2=2) and key = (test2) output will be 2 
Public Function getKeyValue(keyValu,key)
	aryKeyValue =""
	For i = 1 To UBound(keyValu) Step 1
		If key= keyValue(keyValu(i))(0) Then
			getKeyValue= keyValue(keyValu(i))(1)
			Exit For
		End If
	Next
End Function

'GET KEY and VALUE
'Created by : Miah, Create date 06/05/2013
'input Test=1 output will be 1
Public Function keyValue(keyVal)
	spltStr=Split(keyVal,"=")
	If UBound(spltStr) = 0 Then
		keyVal = keyVal & "="
		spltStr=Split(keyVal,"=")
	End If
	spltStr(0) = Replace(spltStr(0)," ","")'blank space not allowed in key
	keyValue = spltStr
End Function

'DELETE EXCEL FILE
Public Function dltExlFile(fPath)
    Set fso = CreateObject("Scripting.FileSystemObject")
    fExist = fso.FileExists(fPath & ".xls")
    If (fExist = True) Then
    	fso.DeleteFile(fPath & ".xls")
    End If
End Function

'REMOVE ANY UNWANTED STRING FROM ORIGIONAL STRING
'strFul = Origional string
'strRemov1 = Any unwanded string first time will remove
'strRemov2 = Any unwanded string second time will remove
Public Function strReplace(strFul)
	Dim strRmov (15)

	strRmov(1)="<html><body><div align=""left"">"
	strRmov(2)="</div></body></html>"
	strRmov(3)="<html>"
	strRmov(4)="<body>"
	strRmov(5)="</html>"
	strRmov(6)="</body>"
	strRmov(7)="<html><body>"
	strRmov(8)="</html></body>"
	strRmov(9)="</span></font></div></body></html>"
	strRmov(10)="</span></font>"
	strRmov(11)="<font face=""Arial""><span style=""font-size:8pt"">"
	strRmov(12)="<div align=""left""><font face=""Arial""><span style=""font-size:8pt"">"
	strRmov(13)="<div align=""left"">"
	strRmov(14)="</div>"
	strRmov(15)="&nbsp;"
	
	strReplace =strFul
	For i = 1 To UBound(strRmov) Step 1
		strReplace =Replace(strReplace, strRmov(i), "") 'Remove all Unwanted character
		strReplace = Replace(strReplace, vbCrLf, "")'Remove new line from the string
	Next
	strReplace =Replace(strReplace, "&quot;", "'")
	
End Function

'Find login information from the text file
Public Function getLogInfo(key)
	getLogInfo=""
	fPath = Environment.Value("txFilePath")

	Set filSys = CreateObject("Scripting.FileSystemObject")
	Set filOpn = filSys.OpenTextFile(fPath) 'Get main text file
    
	Do While filOpn.AtEndOfStream <> True And getLogInfo=""
		redFile = filOpn.ReadLine
    	ck = InStr(redFile, key)
    	If (ck <> 0) Then
    		spltStr=Split(redFile,"=")
			If UBound(spltStr) > 0 Then    		
    			getLogInfo = spltStr(1)
    		End If
     	End If
	Loop ' End For loop here
End Function

UFT RightClick

”UFT / QTP Environment variables for OS
Function invokeApplication(browser)
    OSType = Environment.Value(“OS”)
    OsXp = “Microsoft Windows XP”

    If OSType = OsXp Then
        SystemUtil.Run “C:\Program Files\Internet Explorer\iexplore.exe”
        Else
        SystemUtil.Run “C:\Program Files (x86)\Internet Explorer\iexplore.exe”
    End If
End Function


”Right Click Function using Mercury.ExternObj
RegisterUserFunc PbDataWindowRightClickRightClick
Function RightClick(obj)
On Error Resume Next
Set myExtern = CreateObject(Mercury.ExternObj)
    myExtern.Declare micLong,“GetCursorPos”,“user32.dll”,“GetCursorPos”,micLong
    myExtern.GetCursorPos(NULL)
    myExtern.Declare micLong,“SetCursorPos”,“user32.dll”,“SetCursorPos”,micLong, micLong
    myExtern.SetCursorPos 40199
    myExtern.Declare micVoidmouse_event“user32.dll”mouse_eventmicLongmicLongmicLongmicLong,micLong
    myExtern.mouse_event 84019900 ”mouse down
    myExtern.mouse_event 16401990,0 ‘lift the mouse
Set myExtern = Nothing
    Wait(2)
End Function

”UFT / QTP Test Parameters
Dim enterCACpin
enterCACpin = TestArgs(myCACpin)
msgbox enterCACpin

Monitor Resolution and DPI with QTP/UFT

Monitor Resolution and DPI with QTP/UFT
”Monitor resolution. If you have multiple monitors then it add the width of multiple monitors,
”Returns total width of the monitors and the height of the screens.
screenWidth = Window(“regexpwndtitle:=Program Manager”).GetROProperty(“width”)
screenHeight = Window(“regexpwndtitle:=Program Manager”).GetROProperty(“height”)
MsgBox screenWidth &“x”& screenHeight

”Retrieves the width and height of the primary screen (has the taskbar for windows 7)
screenWidth = Window(“object class:=Shell_TrayWnd”).GetROProperty(“width”)
screenHeight = Window(“object class:=Shell_TrayWnd”).GetROProperty(“height”) + Window(“object class:=Shell_TrayWnd”).GetROProperty(“y”)
MsgBox screenWidth &“x”& screenHeight

”For current Monitor resolution
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery (“Select * from Win32_VideoController”)

For Each objItem in colItems
print “Current Horizontal Resolution: “ & objItem.CurrentHorizontalResolution
print “Current Vertical Resolution: “ & objItem.CurrentVerticalResolution
Next

”Run from Control Panel 
Systemutil.run “control.exe”,“desk.cpl”        ”’Screen resolution
Systemutil.run “DpiScaling.exe”        ”’Font size and DPI

”### Works For Laptop but does not work for Laptop extended monitor
”### Also works For Desktop for single monitor
strComputer = “.”
Set objWMIService = GetObject(“winmgmts:\\” & strComputer & “\root\cimv2”)
Set colItems = objWMIService.ExecQuery _
(“Select * From Win32_DisplayConfiguration”)

For Each objItem in colItems
Print “Name: “ & objItem.DeviceName
Print “Color depth: “ & objItem.BitsPerPel
Print “Horizontal resolution: “ & objItem.PelsWidth
Print “Vertical resolution: “ & objItem.PelsHeight
Next
”#### END ######

”’Find the Desktop DPI is set to smaller 100% or Medium 120%(default)
”’Some Desktop application appears on screen smaller or larger by Desktop DPI
”’If use application’s Y, X cordinate it change by DPI not resolution
”’Finaly set it to Environment Variable, so you can call as many times you want in RunTime
Dim windowsDPI
windowsDPI = ReadReg(“HKEY_CURRENT_USER\Control Panel\Desktop\LogPixels”)”’Windows Desktop DPI
‘msgbox windowsDPI
Environment(“desktopDPI”) = windowsDPI
Function ReadReg(RegPath)
Dim objRegistry, Key
Set objRegistry = CreateObject(“Wscript.shell”)
Key = objRegistry.RegRead(RegPath)
ReadReg = Key
msgbox true
End Function
”’For Example in PowerBuilder Application, sometimes DropDown is used inside a DataWindow
”’ The DropDown contains another DataWindow that is not visible until DropDown is clicked by X, and Y
”’For DPI smaller 100% you can use SelectCellData but if it is Medium 120% then sometimes it does not work
”’Also to create a loop you have to make the DropDown DataWindow visible
If Environment(“desktopDPI”) = 96 Then
PbWindow(“pb_window_name”).PbWindow(“pb_window_name”).PbDataWindow(“pb_DataWindow_name”).Click 342,41
ElseIf Environment(“desktopDPI”) = 120 Then
PbWindow(“pb_window_name”).PbWindow(“pb_window_name”).PbDataWindow(“pb_DataWindow_name”).Click 428,51
Else
Reporter.ReportEvent micWarning, “Desktop Screen”“Desktop DPI is more than 120%” & vbCrLf & “Change DPI from the Control Panel > Display”
End If