Wednesday, February 23, 2011

What is Transactions ?

Sometime you want to know the time script or part of script is taking time to execute in such case Transactions will help to find out.
You define transactions within your test by enclosing the appropriate sections of the test with start and end transaction statements.
How to Inserting Transactions
You define the beginning of a transaction in the Start Transaction dialog box.

·         click the step where you want the transaction timing to start point
·         Insert Start Transaction.
                    


·         The Start Transaction dialog box opens.
·         Enter Transaction name
·         Select radio button as per your need
 To insert a transaction before the current step, select Before current step.
 To insert a transaction after the current step, select After current step.
·         Click OK.
How to Ending Transactions
You define the end of a transaction in the End Transaction dialog box.
·         Click the step where you want the transaction timing to end.
·         Insert End Transaction. The End Transaction dialog box opens.
                         
  • The Name box contains a list of the transaction names you defined in the
Current test. Select the name of the transaction you want to end.
  • Select radio button, where to insert the end of the transaction:
                 To insert a transaction before the current step, select Before current step.
 To insert a transaction after the current step, select After current step.
  • Click OK.

Tuesday, February 22, 2011

What is Exists property in QTP

You can use Exist statements to wait for a window to open or an object to appear.
E.g Browser(“x”).page(“y”).webbutton(“z”).exists

Exists returns Boolean value. Basically, it is used for user define checkpoint

E.g
if Browser(“x”).page(“y”).webbutton(“z”).exists then
            Reporter.Report ,,”pass”
            Else
            Reporter.Report ,,”Fail”
End if

Difference between Exists and Wait
Exists:   Exists will wait till timeout, if object doesn’t exist and return false and start execution
Wait: Wait will wait till default time or user specific time and start execution.

What is Synchronization

Some time running application may not always respond with the same speed. Sometime due to server slow process your response will get late. How to handle such type of situation?

With the use of Synchronization concept in QTP
           
·         Use of Sync property:  You can insert a synchronization point, which tells QTP to pause the test until an object property achieves the value.

E.g. Browser(“x”).page(“y”).webbutton(“z”).sync

  • Use of Wait Statement: You can insert Exist or Wait statements that tell QTP to wait until an object exists or to wait a specified amount of time before continuing the test.
E.g.  
            Wait(10) or Wait // After 10 second, qtp start execution below statement
Browser(“x”).page(“y”).webbutton(“z”).sync

  • Increase timeout time: You can also increase the default timeout settings in the Test Settings and Options dialog boxes in order to tell QTP to allow more time for certain events to occur.
We can set from here File >> Settings >> Run, Increase Object Synchronization timeout limit.

Thursday, February 17, 2011

How to write in Excel Sheet


set xlapp = createobject("Excel.Application")
set wb = xlapp.workbooks.open("D:\test.xls")
set sh = xlapp.worksheets(1)
rc = sh.usedrange.rows.count
for j = 2 to rc

     ' write must be bases on condition
     sh.cells(j,2) = "pass"

Next

xlapp.Visible = True
wb.close
xlapp.quit
set xlapp = nothing

Friday, February 11, 2011

Execution of .vbs or .txt files in qtp

To execute the .vbs or .txt files in qtp, user has to associate those file in qtp

Associate library files in qtp

Concept behind this association of library file is that the script is written in separate library file like .vbs or .txt file and to run script you need to associate those files if you want to use them. After Association of the file, File will place in File -> settings -> resource.

There are two way to execute those files in qtp

1.       ExecuteFile key word
2.       Associate in Library

1.       ExecuteFile keyword:

ExecuteFile "File path" ( E.g: ExecuteFile “C:\test.vbs” )
In this concept, user has to call the function defined the .vbs file. Here library file will not be placed in File -> settings -> resource. But still user can access function defile in the file.
2.       Associate in Library:
Here, run time association of the file will be placed in File -> settings -> resource path in qtp.
Now user can access the function by calling it.

Example:

Set App = CreateObject("QuickTest.Application")
App.Launch
App.Visible = True
App.Test.Settings.Resources.Libraries.RemoveAll
App.Test.Settings.Resources.Libraries.Add "D:\test1.vbs”
App.Test.Settings.Resources.Libraries.Add "D:\test2.vbs"
Set App = Nothing

Note:    Associate file concept will help users to debug in file while run time however ExecuteFile will not be help in debugging.


Thursday, February 10, 2011

Data Table Object Details


1 AddSheet Method

Adds the specified sheet to the run-time Data Table 
      Syntax: DataTable.AddSheet(SheetName)
      Example:
      Variable=DataTable.AddSheet ("Sheet1").AddParameter("Name", "Neeraj")

2.    DeleteSheet Method

Deletes the specified sheet from the run-time Data Table.
Syntax: DataTable.DeleteSheet SheetID
Example: DataTable.DeleteSheet "Sheet1“

3.    Export Method

Saves a copy of the run-time Data Table in the specified location.
Syntax: DataTable.Export(FileName)
Example: DataTable.Export ("C:\FileName.xls")

4.    ExportSheet Method

Exports a specified sheet of the run-time Data Table to the specified file.
Syntax: DataTable.ExportSheet(FileName, DTSheet)
Example: DataTable.ExportSheet "C:\FileName.xls" ,1

5.    GetCurrentRow Method

Returns the current (active) row in the run-time global data sheet.

6.    GetRowCount Method

Returns the total number of rows in the longest column in the global data sheet or in the specified data sheet of the run-time Data Table.
Example:
rowcount = DataTable.GetSheet("Sheet1").GetRowCount

7.    GetSheet Method

Returns the specified sheet from the run-time Data Table.
Example:MyParam=DataTable.GetSheet ("Sheet1").AddParameter("Name", "Neeraj")

8.    GetSheetCount Method

Returns the total number of sheets in the run-time Data Table.

9.    Import Method

Imports the specified Microsoft Excel file to the run-time Data Table.
Syntax: DataTable.Import(FileName)
Example: DataTable.Import ("C:\FileName.xls")

10. ImportSheet Method

Imports a sheet of a specified file to a specified sheet in the run-time Data Table.
Syntax:  DataTable.ImportSheet(FileName, SheetSource,SheetDest)
Example: DataTable.ImportSheet "C:\FileName.xls,1 ,"name"

11. SetCurrentRow Method

Sets the specified row as the current (active) row in the run-time Data Table.
Example: DataTable.SetCurrentRow (2)

12. SetNextRow Method

Sets the row after the current (active) row as the new current row in the run-time Data
Table.

13. SetPrevRow Method

Sets the row above the current (active) row as the new current (active) row in the run-time
Data Table.

14. GlobalSheet Property

Returns the Global sheet of the run-time Data Table.
Example:
DataTable.GlobalSheet.AddParameter "Name", "Neeraj"

15. LocalSheet Property

Returns the current (active) local sheet of the run-time Data Table.
Example:
MyParam=DataTable.LocalSheet.AddParameter("Name ", " Neeraj ")

16. RawValue Property

Retrieves the raw value of the cell in the specified parameter and the current row of the run-time
Data Table.
Syntax: DataTable.RawValue ParameterID [, SheetID]
SheetID can be the sheet name, index or dtLocalSheet, or dtGlobalSheet.

17. Value Property

Retrieves or sets the value of the cell in the specified parameter and the current row of the run-time Data Table.
Syntax:DataTable.Value(ParameterID [, SheetID])

How to use sendkey in QTP script


Definition:
Sends one or more keystrokes to the active window (as if typed on the keyboard).

Syntax:
object.SendKeys(string)

Special character

plus sign       "+",
caret             "^",
percent sign "%",
and tilde       "~"

Send these characters by enclosing them within braces "{}".
For example, to send the plus sign, send the string argument "{+}". Brackets "[ ]" have no special meaning
when used with SendKeys, but you must enclose them within braces to accommodate applications that
do give them a special meaning (for dynamic data exchange (DDE) for example).

To send bracket characters, send the string argument "{[}" for the left bracket and "{]}" for the right one.
To send brace characters, send the string argument "{{}" for the left brace and "{}}" for the right one.
Some keystrokes do not generate characters (such as ENTER and TAB).
Some keystrokes represent actions (such as BACKSPACE and BREAK).
To send these kinds of keystrokes, send the arguments shown in the following table:


Key                                 Argument
BACKSPACE                  {BACKSPACE}, {BS}, or {BKSP}
BREAK                          {BREAK}
CAPS LOCK                  {CAPSLOCK}
DEL or DELETE          {DELETE} or {DEL}
DOWN ARROW          {DOWN}
END                          {END}
ENTER                          {ENTER} or ~
ESC                                  {ESC}
HELP                          {HELP}
HOME                          {HOME}
INS or INSERT          {INSERT} or {INS}
LEFT ARROW          {LEFT}
NUM LOCK                  {NUMLOCK}
PAGE DOWN                  {PGDN}
PAGE UP                  {PGUP}
PRINT SCREEN          {PRTSC}
RIGHT ARROW           {RIGHT}
SCROLL LOCK          {SCROLLLOCK}
TAB                                  {TAB}
UP ARROW                   {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}

Example



Const iNormalFocus = 1
Set objShell = WScript.CreateObject("WScript.Shell")
objShell.Run "mmc.exe",iNormalFocus

Wscript.Sleep 300

objShell.AppActivate "Console1"
Wscript.Sleep 100
objShell.SendKeys "^m"
Wscript.Sleep 100
objShell.SendKeys "{TAB}"
Wscript.Sleep 100
objShell.SendKeys "{TAB}"
Wscript.Sleep 100
objShell.SendKeys "{ENTER}"