Showing posts with label Advanced QTP. Show all posts
Showing posts with label Advanced QTP. Show all posts

Thursday, July 31, 2014

Check if web Page has horizontal and vertical Scrollbars

The following code will be able to tell if the web page has a horizontal or vertical scrollbars. And function GetScrollbarState accepts two arguments:
1. The  document (i.e., Browser(“MyBrowser”).Page(“MyPage”).Object)
2. The direction of the scrollbar – “h” for horizontal or “v”” for vertical. 
This function will returns true or false if there is a scrollbar in the given direction

Function GetScrollBarState(ByRef document, ByVal scrollbarDir)
    Dim result
    Dim root    
    OnErrorResumeNext
    SelectCase LCase(document.compatMode)
        Case"backcompat"
            Set root = document.body
        CaseElse
            Set root = document.documentElement
    EndSelect
    
    SelectCase LCase(scrollbarDir)
        Case"h"
            scrollbarDir = "horizontal"
            result = (root.scrollWidth > root.clientWidth)
        Case"v"
            scrollbarDir = "vertical"
            result = (root.scrollHeight > root.clientHeight)
    EndSelect    
    
    If Err.Number <> 0 Then
        Reporter.ReportEvent micWarning, "GetScrollBarState", "Could not get state for " & scrollbarDir & " scrollbar"
        result = "Undefined"
        Err.Clear
    EndIf
    GetScrollBarState = result
EndFunction
 
 
The following two functions will be used as Page properties using QTP/UFT RegisterUserFunc:
 
Function HasHorizontalScrollbar(ByRef oPage)
    HasHorizontalScrollbar = GetScrollBarState(oPage.Object, "h")
EndFunction
 
Function HasVerticalScrollbar(ByRef oPage)    
    HasVerticalScrollbar = GetScrollBarState(oPage.Object, "v")
EndFunction
 
RegisterUserFunc "Page", "HasHorizontalScrollbar", "HasHorizontalScrollbar"
RegisterUserFunc "Page", "HasVerticalScrollbar", "HasVerticalScrollbar"
 
'Usage with QTP/VBScript Code
Set oPage = Browser("Browser").Page("Page") 
Print oPage.HasHorizontalScrollbar
Print oPage.HasVerticalScrollbar

**** Special thanks to Meir Bar-Tal for such a great function which made our work easy *****

Monday, August 29, 2011

How do I sort arrays items using vbscript?

we will be able to sort in alphabetically an array items using the vbscript.

' declaring the array
Dim arrSortOut(10)
' assigning data to the array
arrSortOut(0)="Ammu"
arrSortOut(1)="Siva"
arrSortOut(2)="Madhu"
arrSortOut(3)="Ranga"
arrSortOut(4)="Jagadesh"
arrSortOut(5)="Kumar"
arrSortOut(6)="Praveen"
arrSortOut(7)="Martha"
arrSortOut(8)="Zeebra"
arrSortOut(9)="123Zeebra"
arrSortOut(10)="!123Zeebra"

for i = UBound(arrSortOut) - 1 To 0 Step -1
  for j= 0 to i
    if arrSortOut(j)>arrSortOut(j+1) then
      temp=arrSortOut(j+1)
      arrSortOut(j+1)=arrSortOut(j)
      arrSortOut(j)=temp
   end if
  next
next


for x=0 to 8 UBound(arrSortOut)
 msgbox arrSortOut(x)' to check the items
next

How to Maximize/Minimize a Browser?

you can maximize or minimize your browser (AUT) using the below simple script.

If Browser("abc").Exist Then
    Brw_Hwnd = Browser("abc").GetROProperty("hwnd")
    Set a= Description.Create
    a("hwnd").Value = Brw_Hwnd
    Window(a).Maximize'to maximize application browser
    'Window(a).Minimize' to minimize application browser
End If
Follow Me on Twitter

How to get Tool tip of Images in a web page?

Now it's very easy to get tool tip from an images in the web pages, by using the below script.
Browser("abc").Page("abc").Sync
Set desc_img = Description.Create
desc_Img("html tag").value = "IMG"
Set list_imgs= Browser("abc").Page("abc").ChildObjects(desc_img)
   For i = 0 To list_imgs.Count - 1
     tool_tiptxt= list_imgs(i).GetROProperty("alt")
     If tool_tiptxt <> "" Then
       MsgBox "Tool tip text= " & tool_tiptxt
     End If
  Next

Thursday, August 25, 2011

How to get Sub-folders Count and Names from a Folder?

How to get Sub-folders Count and Names from a Folder? using the below code(VB Script) you will be able get all the sub-folders in a parent folder.  This code will be very much useful in the during the creation of Test Automation Frame works.


Set Obj = CreateObject("Scripting.FileSystemObject") 
'Creating a file system object
    Set Obj1 = Obj.GetFolder("C:\test")
    Set Obj2 = Obj1.SubFolders
    msgbox Obj2.Count 'displaying count of sub-folders
    For Each Fold_Iteam in Obj2
        Fold_names = Fold_names& Fold_Iteam.name &vbnewline
Next
msgbox Fold_names 'Displaying all sub-folders names

Lock your system after execution of your QTP Script

Now you can lock your system after your QTP batch script/script execution.
use the below code at the end of your script(batch/regular). your system will be automatically locked,once after script executed.
Public Function Lock_your_system()
    Set obj = CreateObject("WScript.Shell")
    sCmnd = "%windir%\SYSTEM32\rundll32.exe user32.dll,LockWorkStation"
    obj.Run sCmnd, 0, False
End Function