Monday, August 29, 2011

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

How to get the font color of an item in a WebList ?

with the below simple script you will be able to get font, item name and font color of weblist items.

set Web_list_Items= Browser("abc").Page("abc").WebList("abc").Object.all.tags("option")
For each element in Web_list_Items
   Set style = element.currentstyle
   Item_text_color=style.Color
   Item_text=element.text
   msgbox Item_text_color
   msgbox Item_text
Next

Friday, August 26, 2011

Action Template in QTP

How to create a Action Template in QTP?

Every time you open New script in QTP you will get a blank window in Expert view, but if you want to view the Standard header commented section with the automation Standards, you can create a Template which you can use for all the scripts to view the same set of instructions/Standards, and also you can pass all other team members to use the same.

Just follow the bellow simple steps to create Action Templete....

1. Create a text file with what all things need to be in the script.
2. Save as this text file as ActionTemplate.mst file in the
     C:\Program Files\hp\QuickTest Professional\dat Folder.
3. Now Click on new script in QTP.
     You will get what ever text you have kept in the template !!!!!

Scripting Guidelines or Coding Standards in Test Automation Script

Coding Standards are suggestions that will help you to write QTP Script code using VB Script. Naming conventions for crating QTP Script, objects, variables and procedures. Commenting standard in the scripting, Text formatting and align guidelines for the script.

The main motive for using a regular set of coding Standards is to normalize the structure and coding way of a QTP script or set of scripts, so that you and others team members can easily read and understand the QTP code.
Using good coding standards will results in accurate, readable, and unmistakable QTP Script.
Code that is consistent with other languages like Java script etc,. conventions and as sensitive as possible.

Script Organization


An example of the comment block is as follows:

you can also create a action template, with fallowing information, Click Here to see how to create a action template in QTP.

'Test Script Header
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'@Script Name : < Name of the Script>
'@Script Description : < Description of the Script>
'@Script Author : < Jr.Siva Kumar Eanuga>
'@Email ID: < Shivakumar004@gmail.com>
'@CreationDate : < dd-mm-yyyy>
'@Last Updated Date : < dd-mm-yyyy>
'@PreCondition : < pre requisites to be used for the script>
'@Libraries : < required library files>
'@External Function Reference:
'@DataFiles : < required data files>
'@DtParam : < Name>
'@DtParam : < Name>
'@DtParam : < Name>
'@Modification : < By , Date: >
'@Description: < modification description>
'@Reviewed By : < Sr. Siva Kumar Eanuga>
'@Reviewed Date : < dd-mm-yyyy>
'@Remarks : < Additional information>
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option Explicit
'-- Constant Declarations
'declare here your constants
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'--- Global Variable Declarations
'declare here your Global Variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'--- Local Variable Declarations
'declare here your Local Variables
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'< detailed script>

''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' The End of Script
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

Standards of Constant Naming

Constant names should be uppercase with underscores (_) between words.
Ex: USER_LIST_MAX, NEW_LINE

Standards of Variable Naming

For easy readability purpose use the prefixes like below examples, along with descriptive names for variables in your QTP Script code.
Ex:
String -- sName
Object -- oObjectname
Integer, Byte, Long -- nNumber
Array -- arrListitems
Boolean -- bYes
Single, Double -- fPrice
DateTime -- dToday
Error -- errResponse
Currency –- cRupees

Object Naming Standards

For the objects we create in the QTP script, we use prefix “o” (small letter o).

Ex:
ADODB.Connection -- oConn
ADODB.Recordset -- oRset
Scripting.xmlobject -- oXmlobj
Scipting.FileSystemObject -- oFsobj
Scipting.TextStream -- oTxt
Scripting.Dictionary -- oDic
Shell.Application -- oWsh
Excel.Application -- oXls

to be continued .....

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