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

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