Friday, April 12, 2013

Environment variables

How is an environment variable defined at run time?


           Environment(“Test Name”)=val

                 Note : The act of assigning a value to a non-existent environment variable causes QTP to implicitly create and initialize the variable.



How external variables laoded from an external XML file during run time?

          Environment.LoadFromFile “path”

How is an environment variable cleared or destroyed?

          Environment(“Test Name”)=”test”
          Environment(“Test Name”)=Nothing
 
Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Environment Variables

QTP Environment variables are variables which we can share information across actions, recovery scenarios and libraries.

These environment variables are different from Windows environment variables.

Windows environment variable are available to all the programs running on the machine while QTP environment variables are only available to a test script running at run-time.

Types of Environment variables:

There are three types of Environment variables in QTP:

1.       Built-in :  QTP provides a variety of environment variables that define information such as the currently executing test’s name, the test’s path, the operating system type and its verision and the local host name.

To Check Built-in environment variables:

File -> Settings -> Environment tab -> From Variable type drop down select ‘BuiltIn’

Ex: msgbox environment(“OS”)

     Msgbox environment(“Prod Dir”)

2.       User defined Internal :  These variables are defined in a test and saved with the test. These variables can be modified during run-time.

Accessing User defined internal variables:

File -> Settings -> Environment tab -> From Variable type drop down select ‘User defined’ -> Click on ‘+’ button and enter environment variable name and value -> click on OK button.

3.       User Defined External : 
These variables are defined in an external environment files. These variables are read-only and cannot be modified at run-time. The external file can be associated with the test.

Accessing User defined external variables:

File -> Settings -> Environment tab -> From Variable type drop down select ‘User defined’ -> Click on ‘+’ button and enter environment variable name and value -> Click on Export button and save the corresponding file. -> Open a new test -> File -> Settings -> Environment tab -> From Variable type drop down select ‘User defined’ -> Check the Load variables and values from external files check box -> browse the corresponding environment file. -> Click Apply -> Click OK
Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Wednesday, April 10, 2013

Display values for Fly From and Fly To dropdown values to Excel sheet



Option Explicit
Dim flyFromCnt,itemNum
Window("Flight Reservation").Activate
flyFrmCnt=window("Flight Reservation").WinComboBox("Fly From:").GetItemsCount

For itemNum=0 to flyFrmCnt - 1
          datatable.SetCurrentRow(itemNum)
          datatable("FlyFrom",1)=Window("Flight Reservation").WinComboBox("Fly From:").GetItem(itemNum)
          datatable("FlyTo",1)=window("Flight Reservation").WinComboBox("Fly To:").GetItem(itemNum)
Next

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com

Verify login functionality for different valid and invalid values - flight app



(Note: First manually need to prepare input.xls file with list of valid and invalid values and save in desired path.)

Option Explicit
Dim rowCnt,rowNum
Datatable.ImportSheet "D:\input.xls",1,2
rowCnt=Datatable.GetSheet(2).GetRowCount
For rowNum=1 to rowCnt
 SystemUtil.Run "C:\Program Files\Mercury Interactive\QuickTest Professional\samples\flight\app\flight4a.exe"
          Dialog("Login").WinEdit("Agent Name:").Set datatable("uname",2)
          Dialog("Login").WinEdit("Password:").Set datatable("pwd",2)
          Dialog("Login").WinButton("OK").Click
          If Dialog("Login").Dialog("Flight Reservations").Exist Then
                   Reporter.ReportEvent micFail,"Verify login functionality","Login functionality is not working"
                   Dialog("Login").Dialog("Flight Reservations").Close
                   Dialog("Login").WinButton("Cancel").Click
                   datatable("result",2)="Fail"
          Else
                   Window("Flight Reservation").Close
                   Reporter.ReportEvent micPass,"Verify login functionality","Login functionality is working"
                   datatable("result",2)="Pass"
          End If
          Datatable.SetNextRow
Next
Datatable.ExportSheet "D:\output.xls",2   

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

Import values from xls to datatable



Import value1 values from sample1.xls  file, import value2 values from sample2.xls file, add value1 and value2 values and display in result colum and export final output result file.
         
datatable.ImportSheet "D:\VJProjects\QTP Demo\sample1.xls",1,1
datatable.ImportSheet "D:\VJProjects\QTP Demo\sample2.xls",1,2
datatable.AddSheet("result")
datatable.ImportSheet "D:\VJProjects\QTP Demo\sample3.xls",1,3
For rowNum=1 to datatable.GetRowCount
                   val1=datatable("first",1)
                   val2=datatable("second",2)
                   datatable.GetSheet(3).GetParameter("first").valueByRow(rowNum)=val1
                   datatable.GetSheet(3).GetParameter("second").valueByRow(rowNum)=val2
 val3=cint(val1)+cint(val2)
                   datatable.GetSheet(3).GetParameter("result").valueByRow(rowNum)=val3
                   datatable.SetNextRow
          Next

Contributed by: Vamshi Gowtham
m.vamsigowtham@gmail.com 

AI in Software Testing: How Artificial Intelligence Is Transforming QA

For years, software testing has lived under pressure: more features, faster releases, fewer bugs, smaller teams. Traditional QA has done her...