Monday, October 10, 2011

Dictionary Object


Scripts often retrieve information from an outside source, such as a text file or a Database. After this information has been retrieved, it needs to be stored in Memory so that the script can act upon it. Information such as this can be stored Dictionary object.

The Dictionary object functions stores values in key-item pairs. The Dictionary object is similar to a Collection object .Like an array or a Collection object, Dictionary object holds elements, called items or members, containing data. A Dictionary object can contain any data whatsoever, including objects and other Dictionary objects. Access the value of these dictionary items by using unique keys (or named values) that are stored along with the data. Dictionary is a COM object.
Creating Dictionary
Set oDictionary = CreateObject("Scripting.Dictionary")
Adding Key-Item Pairs to a Dictionary
Set oDictionary = CreateObject("Scripting.Dictionary")
oDictionary.Add "Fax", "Faxing"
Here the Key is Fax and Key Value is Faxing

Descriptive Programming:QTP


As I described earlier that how QTP identifies test objects during execution.

The answer is simple that during run time it recognize the test object by referring to its object repository ,where we already have stored test object earlier(before creating any test we must make QTP to learn all the test required test object and store it in object repository).

Now the Question is the application is not ready then there is no test object available, then how QTP will learn the test objects and what will we store in the object repository??

Now answer may be the one of the following or all
    1)    It is impossible to automate any application which is not ready.
    2)    QTP cannot work without Object repository.
    3)  What QTP will learn and where will it store.

But all of the above answers are totally wrong J

There is concept/technique which is known as Descriptive Programming is the solution for those.
If we are using object repository then during the run session, QTP finds the object in the object repository based on its name and parent objects, and uses the stored test object description for that test object to identify the object in the application.
We can also instruct QTP to perform operations on objects without referring to the object repository or to the object's name. To do this, we provide QTP with a list of properties and values that QTP can use to identify the object or objects on which we want to perform an operation. This technique is known as Descriptive Programming (inserting programming descriptions).
There are two types of programmatic descriptions:
<!Static. List the set of properties and values that describe the object directly in a VBScript statement
       Synatx:  Testobj(“Propname1:=PropVal1” , “Propname2:=PropVal2”)
              TestObject. The test object class.
            PropertyName:=PropertyValue. The identification property and its value.
            Each   property:=value pair should be separated by commas and quotation marks

Example :
  Browser("Title:=Mercury Tours").Page("Title:=Mercury Tours").WebEdit("Name:=Author",   "Index:=3").Set "Alok"
2) Dynamic.  Add a collection of properties and values to a Description object, and then enter the Description object name in the statement.
The Dynamic type provides more power, efficiency, and flexibility.
We can use the Description object to return a Properties collection object containing a set of Property objects. A Property object consists of a property name and value. We can then specify the returned Properties collection in place of an object name in a statement. (Each property object contains a property name and value pair.)
To create the Properties collection, you enter a Description. Create statement using the following syntax:
Set MyDescription = Description.Create()
Example:
Set Objbtn = Description.Create()
Objbtn(“value”).Value =  Google Search”
Objbtn(“type”).Value = “submit”
Browser(“Google”).Page(“Google”).WebButton(Objbtn).Click
Note: For getting the object properties and their values respectively please refer the Object Spy section described in earlier posts http://expertqtp.blogspot.com/2011/05/object-spy-in-qtp.html




Wednesday, October 5, 2011

QTP: Recovery scenarios in QTP

Recovery Scenarios
Unexpected events during a test run disrupt a test or may give invalid test results. For example, during a test run, an application error may occur. This error does not permit the automated test to navigate to the feature, screen, or module that needs to be tested. These unexpected errors and events are called exceptions.
Recovery scenarios are used when you cannot predict at what step the error can occur .
When QTP encounters an exception during a run session, it displays a run error window.
A recovery Scenario consists of the following components:
Trigger: Specifies the exception that may occur during a run session.
The following are the 4 trigger event that QTP provides.
1.Pop up window
2.Object state
3. Test run error
4.Application crash
Recovery: Instructs QTP how to handle the exception
Post-Recovery: Instruct QTP how to proceed after the recovery operations are performed.
The following are the 6 Post-Recovery steps that QTP provides
1) Repeat current step and continue
2) Proceed to next step
3) Process to next action or component iteration
4) Proceed to next test iteration.
5) Restart current test run.
6) Stop the test run.

Tuesday, October 4, 2011

QTP Interview Questions:QTP

Hi Friends the few are some questions which are related to QTP interview ,which may be useful.

QTP Interview Questions -1

1) What are the advantages in Test Automation?

a)  Fast: Test Tool runs tests significantly faster than human users.

b) Reliable: Automation tool can perform the same operation each time, if we repeated multiple times, so that we can eliminate human errors.

c)  Repeatable: We can check how application or website reacts after repeated the same operation with multiple times.

d) Reusable: Automation scripts are reusable on different version of the application of websites even if the user interfaces changes.

e)  Comprehensive: In automation testing we can build a suit of tests that covers every feature in the application or website.

f)  Programmable: We can program sophisticated Tests that bring out hidden information from the application

2) What are the drawbacks in Test Automation?
a) It is expensive
b) We cannot automate all areas.
c) Lack of Skill
d) It has some limitations (It cannot test every thing)

3) What type of test tools available in the industry?

We can segregate Test tools in 2 categories

a) Business Classification

     1) Vendor Tools
     2) Open Source Tools
     3) In-house Tools


b) Technical Classification
    
     1) Functional and Regression Test Tools
     2) Load/Stress/Performance Test Tools
     3) Security Test Tools
     5) Test Management Tools
     6) Unit Test Tools
     7) Requirement Management Tools Etc...


4) What are the important factors in test tool selection?

a. Technical factors:

i. Nature of the AUT (Application Under Test)
ii. Tool Features (Facilities available)
iii. Availability of Skilled professionals
iv. Organizations experience
v. Technical support from vendor

b. Business factors:

i. Budget
ii. Vendor’s Reputation
iii. Client’s Interest

5) What test cases can be automated?

Test cases that we want to execute on number of versions of the software
Ex: Regression test cases
Test cases that we want to execute with multiple sets of data
Ex: Data driven test cases
Test cases having complex functionality

6) What test cases cannot be automated?

o Dynamically changing functionality
o Test cases that require more Human interaction
o CUI (command user interface) based test cases

7) Explain about the Testing process in QTP?
Planning:
o Analyzing the Application
o Automation Framework Implementation
o Selecting/Generating Test cases for Automation
o Collecting Test Data
o Configuring Tool Settings
Generating the basic tests
Using Object Repository method or using Descriptive Programming, we can generate Tests
Enhancing Tests
With respect to our project requirements, we have to enhance our tests. For enhancing tests QTP is providing various features like:
o Inserting Transaction points
o Synchronization
o Parameterization
o Inserting VB script Flow Control statements
o Adding comments
o Calling Functions/ calling Actions
o Using Environment variables
o Entering Regular Expressions
o Inserting Checkpoints
o Inserting Output values
Etc..
Note: For any Test all enhancement methods not required.

Debugging Tests (if required)
It is optional; basically scripting languages are Light weight languages, no need to compile them separately. During execution Scripts can be compiled and Run.
If we have any doubts about some scripts, then we can execute them step by step with the support of VBScript Debug commands and Break points

Running tests
Generally, many companies are using Framework feature for Running Tests.
QTP Supports Individual Test execution, Batch execution, Tests execution through AOM Scripting, and Scheduled execution with the support of Windows Operating system.

Analyzing Results
It is not the Responsibility of QTP; Test engineer has to do this manually.
QTP is providing Result window in XML format.
QTP is providing Result deletion tool also.
QTP is providing Test results exporting facility. It supports HTML, Word document and PDF (portable document format) formats.

Reporting defects
Reporting defects also not a QTP responsibility that we have to do manually after analyzing the results, but if we are using Quality Center, from QTP result window we can send defects directly.

8) What types of License available for QTP?

a) Seat License or Node locked

Fixed for one System (Machine), we can use from that System only

b) Concurrent License or Floating License

This License, we can use from different Systems but one at a time

9) What are the QTP supported environments?

QTP Supports Software Applications based on Add-ins only

Add-in means Technology supporting files

QTP Add ins available for following technologies:

a) Default Add ins

1) Activex
2) Visual Basic
3)  Web

b) Other Add-ins
1) Delphi
2) Java
3) .NET Web forms
4) .NET Windows forms
5) WPF (Windows Presentation Foundation)
6) Oracle
7) People Soft
8) Power Builder
9) SAP for Web
10) SAP GUI for windows environment
11) Siebel Environment
12) Standard Windows
13) Terminal Emulator (TE)
14) Visual Age Smalltalk Environment
15) Web Services Environment

10) Does QTP Support UNIX Environment?

No, QTP doesn’t support UNIX/Linux Environment, Supports Windows Operating Environment only, but LoadRunner and Quality Center have support both Windows and UNIX Operating Environments.

11) What is the scripting language that used in QTP for applying programming logic?

Micro Soft Visual Basic Scripting edition (VBScript) engine embedded with QTP.

12) Does QTP Support Database Testing and Data driven Testing?

Yes, SQL Engine embedded with QTP Tool, so we use SQL Statements directly in QTP Test Pane as well as in Function Library.

QTP has an integrated Spread sheet(Excel like) for Performing Data Driven Testing, otherwise we can fetch test data directly from  external files and databases using VB Script.

QTP Interview Questions -2

1) What is Recording in QTP?
It is process of creating the main body of a test by recording the typical processes that users perform.

QuickTest records the operations we perform, displays them as steps in the Keyword View, and generates them in a script (in the Expert View).
2) How many Recording Modes available in QTP? What are they?


There are 3 Recording modes available in QTP.
     1) Normal Recording
     2) Analog Recording
     3) Low Level Recording


3) What is Analog Recording mode?

It Records exact mouse and keyboard operations, we can use this mode for recording continues mouse operations like digital signatures, paints etc..

This mode doesn't generate statements for each and every operation, generates all operations in a Track file.


By default this mode is disabled, after selecting Normal Recording mode only it enables.


4) What is Low Level Recording?


It Records some operations on Non-supported environments apart from Normal operations.


5) What are object and Software Objects?

Object: Object is something, which has structure and properties.

Software Object: an object is any entity that can be manipulated by the commands of a programming language, such as a value, variable, function, or data structure.

Example:

GUI (Windows) Environment: Window, Dialog box, Edit Box, Button, Check Box, Radio Button, List Box and Combo Box etc...

Web Environment: Browser, Page, Link, Image, edit Box, Button, Grid, Frame Etc..


6) What type of Objects available in QTP?

There are 4 types of Objects available in QTP.

     1) Run-time Objects
     2) Test Objects
     3) Utility Objects
     4) Automation / User Defined Objects


7) What are Utility Objects?

These are QTP reserved objects, used for Testing and Result reporting.

Example:

a) SystemUtil
b) Reporter
c) DataTable
d) Services
e) environment etc...


8) What is Automation Object?

An object that is exposed to other applications or programming tools through Automation interfaces.


9) Explain about Object, Property and value?

Object:  It is something which has structure and properties


Property: an attribute of an Object.

Value: Value of the Property


10) What is Object Repository?

It is a Storage place for Storing Objects, QTP has 2 types of Repositories.

  a) Local Repository
  b) Shared Repository


11) What are the differences between Local  and Shared Repositories?

Local Repository:

QTP Creates a Local Repository for every Action during Recording automatically and also QTP maintenance Local Repositories, but user can edit these repositories.

It is a QTP Internal file, extension is .mtr
 
Shared Repository:

User  Creates Shared Repositories by adding objects in Object Repository Manager.This can be shared among nuber of tests.

User has to maintain shared repository files

Shared Repository files are External files, extension is .tsr 


12)  How to Start Test Automation Process, before the Application is ready?

QTP is providing a feature called "Define New Test Object" for creating new objects without Application. This feature available in Local Repository and Object Repository Manager.


13) How to Combine Repositories?

We Can combine Repositories using Object Repository Merge Tool. It is available in Object Repository Manager


14) Explain about Statement, Action and Test in QTP?
   
      a) Statement: an Instruction or a minimal executable unit
      b) Action: Set of Statements
      c) Test: One or more Actions


15) How Load repository files During run-time?


We can Load Object Repositories during run-time using an Utility object called "RepositoriesCollection"

Syntax:
RepositoriesCollection.Add  "path of the Repository file"

Example:

RepositoriesCollection.Add  "D:\ALOK\Login.tsr"

Monday, October 3, 2011

Business Process Testing : QTP

This topic will guide you about BPT and how to work with BPT.
BPT Methodology
1)      BPT is Business Process Testing
2)      Additional module in QC and is known as Business Component
3)      Test Scripts are associated with components.
4)      Components are easily maintained, reusable units that perform a specific task.

QTP provides two types of components:

1) Business component
Business components (also known as keyword-driven components) are fully integrated with both QuickTest and Quality Center.

2) Scripted component
Scripted components are more complex components containing programming logic.

Pre-requisite for BPT:

1) Install BPT Add-Ins.
2) Check the Allow the Mercury Products to run test and components
checkbox in Options>Run tab.

BPT Strategy / Approach
1)      Initially start with creating the scripted components from Business Component tab in QC.
2)      Pull the respective components to the Test Plan from Component Folder in QC as per manual test case.
3)      Pull the Test scripts to Test Lab for regressions.
4)      Execute and Analyze the results and log the defects if any failure occurs.

Scripted Component:
Two ways to create a component
1)  From QC> Go to Business Component tab> Click on New >Enter the component name > OK
2) From QTP> Connect to QC> New> Select Scripted Component>Enter the component name> OK.
Once after create the component in QC, we can find some tabs at right side pane in QC. Like Details, Snap shot, Design steps, Automation. We need to fill the information in these areas.
Details tab: Provides a general summary of the components purpose or
goals, and the condition of the application before and after a component is
run (its pre-conditions and post-conditions).

Snap shot tab: Displays an image that provides a visual cue or description of the components purpose or operations.

 Parameter tab: Specifies the input and output component parameter values for the business component. Implementing and using parameters enables a component to receive data from an external source and to pass data to other components in the business process test flow.
 Design Steps: Enables you to create or view the manual steps of your business component, and to automate it if required.
Automation tab: Provides access to automated component by choosing it to scripted component.


The component has 4 status:

1. Error: When Component is error for some reason like May be Test case is incorrect or May be made a mistake or May be created a wrong component, in such cases you set to Error
status and provide with meaningful comment, displayed in Red color.
2. Ready: Once the component is completed include debugging and enhancement then the component is Ready status, displayed in Green.
3. Under Development: When a new Component is to be created then the component is Under Development, displayed in Grey.
4. Maintenance: When the requirements changed then component is under Maintenance, displayed in Yellow

Parameterization:
Process to replace the constant values with variables is known as Parameterization.
There are 2 parameters:
1. Input Parameter:
With this parameter, you can input the data to the application.
This Input Parameter is also called Component Parameter
Its another one more parameter especially for BPT apart from other parameters.
We can find this as Component Parameter from the list in Keyword View
Syntax is Parameter(<name of parameter>)

2. Output Parameter:
With this parameter, you can retrieve the data from the application. Parameterization can be done in 2 ways for Input Parameters.

Application Area:
An application area, provides a single point of maintenance for all elements
associated with the testing of application. These include function libraries, shared
object repositories, keywords, testing preferences, and recovery scenarios.
From QTP>New > Application Area
Creation of Test Script
1)      From Test Plan> Click New Test> Select BPT> Enter the name of
the script> OK
The icon will be created at left side panel.
2)      Once created the script, List the all manual test cases, one which are related to this script under Details tab.

3)      From Test Plan, pull the respective components under Test Script
Arrange the components in a work flow by moving the components up and down.
4)      If the components have any parameters then displayed as link.
5)      Click on this link, Component Iteration window will pop up. It just resembles the excel, where you enter the test data or import/export from external resource.

Regression Suite:
1)      All the Test scripts are pulled to Test Lab for the regression testing.
2)      Set to run the suite from one or more systems remotely.
3)      Analyze the results.

Benefits of BPT Process
1)      Each component is by default a reusable.
2)      There is no concept of multiple actions. It means each component is single action.
3)      Business process tests are created and implemented more quickly than other automated tests.
4)      Reduces maintenance compared to traditional automation.
5)      Data-driven testing can be performed effectively.

Scripting ADODB:QTP

ADODB - Microsoft ActiveX Data Object 1. ADO is a Microsoft technology.
2. ADO stands for ActiveX Data Objects.
3. ADO is a Microsoft Active-X component
4. ADO is automatically installed with Microsoft IIS
5. ADO is a programming interface to access data in a database

ADO-ActiveX Data Objects
Microsoft® ActiveX® Data Objects (ADO) enable your client applications to access and manipulate data from a variety of sources through an OLE DB provider. Its primary benefits are ease of use, high speed, low memory overhead, and a small disk footprint. ADO supports key features for building client/server and Web-based applications.

RDS
Remote Data Service (RDS) is a feature of ADO, with which you can move data from a server to a client application or Web page, manipulate the data on the client, and return updates to the server in a single round trip.

OLEDB
OLEDB (sometimes written as OLEDB or OLE-DB) is an API designed by Microsoft for accessing different types of data stores in a uniform manner. It is a set of interfaces implemented using the Component Object Model (COM); it is otherwise unrelated to OLE. It was designed as a higher-level replacement for, and successor to, ODBC, extending its feature set to support a wider variety of non-relational databases, such as object databases and spreadsheets that do not
necessarily implement SQL. OLE DB separates the data store from the application that needs access to it through a set of abstractions, such as connections, record sets and attributes. This
was done because different applications need access to different types and sources of data and do not necessarily want to know how to access functionality with technology-specific methods. OLE DB is conceptually divided into consumers and providers. The consumers are the applications that need access to the data, and the provider is the software component that implements the interface. OLE DB is part of the Microsoft Data Access Components (MDAC) stack and is the database access interface technology. MDAC is a group of Microsoft
technologies that interact together as a framework that allows programmers a uniform and comprehensive way of developing applications for accessing almost any data store. OLE DB providers can be created to access such simple data stores as a text file or spreadsheet, through to such complex databases as Oracle, SQL Server and Sybase. However, because different data store technology can have different capabilities, OLE DB providers may not implement every possible interface available to OLEDB. The capabilities that are available are implemented through the use of COM objects - an OLE DB provider will map the data store technologies functionality to a particular COM interface. Microsoft calls the availability of an interface to be
"provider-specific" as it may not be applicable depending on the database technology involved. Additionally, however, providers may also augment the capabilities of a data store - these capabilities are known as services in Microsoft parlance.

ODBCThe Microsoft Open Database Connectivity (ODBC) interface is a C programming
language interface that makes it possible for applications to access data from a
variety of database management systems (DBMSs). The ODBC interface permits
maximum interoperability — an application can access data in diverse DBMSs
through a single interface. Furthermore, that application will be independent of any
DBMS from which it accesses data. Users of the application can add software
components called drivers, which interface between an application and a specific
DBMS.

The functions in the ODBC API are implemented by developers of DBMS-specific
drivers. Applications call the functions in these drivers to access data in a DBMSindependent
manner. A Driver Manager manages communication between
applications and drivers.

Applications that use ODBC are responsible for any cross-database functionality.
For example, ODBC is not a heterogeneous join engine, nor is it a distributed
transaction processor. However, because it is DBMS-independent, it can be used
to build such cross-database tools.

Connection.Open Method:
Syntax: object.Open (ConnectionString, UserID, Password, Options)

Connection.OpenSchema Method

Syntax: object.OpenSchema (QueryType, Criteria, SchemaID)

Example:
***************************************************************************

Option Explicit
Const adSchemaTables = &H14
Const adSchemaColumns = 4
Const adStateOpen = 1
Dim oConn, oRst, oRstSchema
Dim nRow
Dim sColumn
Set oConn = CreateObject("ADODB.Connection")
'--- Opening Database via DNS
oConn.Open "QT_Flight32"
'--- Open schema Tables
Set oRst = oConn.OpenSchema(adSchemaTables)
Do Until oRst.EOF
'--- Skip system tables
If StrComp(oRst("TABLE_TYPE").Value, "SYSTEM TABLE") <> 0 Then
sColumn = DataTable.LocalSheet.AddParameter( _
oRst("TABLE_NAME").Value, "").Name
'--- Querying Schema table columns
Set oRstSchema = oConn.OpenSchema(adSchemaColumns, _
Array(Empty, Empty, "" & oRst("TABLE_NAME").Value))
nRow = 1
DataTable.LocalSheet.SetCurrentRow nRow
Do While Not oRstSchema.EOF
DataTable(sColumn, dtLocalSheet) = _
oRstSchema("COLUMN_NAME").Value
oRstSchema.MoveNext
nRow = nRow + 1
DataTable.LocalSheet.SetCurrentRow nRow
Loop
End If
oRst.MoveNext
Loop
'--- Close the recordset schema if opened.
If oRstSchema.State = adStateOpen Then oRstSchema.Close
'--- Close the recordset if opened.
If oRst.State = adStateOpen Then oRst.Close
'--- Close the connection if opened.
If oConn.State = adStateOpen Then oConn.Close
Set oRst = Nothing : Set oConn = Nothing : Set oRstSchema = Nothing
***************************************************************************
OutPut:


OutPut:

Sunday, October 2, 2011

Scripting Excel : QTP

Drives, files and folders are the lifeblood of any organization; this makes file
system administration one of the most important responsibilities assigned to
system administrators. Of course, file system administration is also one of the
More difficult responsibilities to carry out, simply because files and folders are
Scattered on multiple hard disks and multiple computers throughout the
Organization. Scripts can help make file system management much easier,
Particularly when the files and folders managed, are located on remote computers.

1) Creating Excel Application Object

Syntax: Set ObjVar = CreateObject("Excel.Application")'Create
Examples: Excel ApplicationObject
Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objExcel.Workbooks.Add
By running the preceding script, you really did create a brand-new instance of Microsoft Excel. Press CTRL-ALT-DEL and take a look at the Processes tab in the Task Manager. You should see an instance of Excel.exe


Examples:
-----------------------------------------------------------------------------------------
1) 'Create Excel file /Work book

Dim objExcel
Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True 'To make the excel visible
objExcel.Workbooks.Add ‘Adding a work book
objExcel.ActiveWorkbook.SaveAs "D:\ALOK\alok.xls"
objExcel.Quit
Set objExcel=Nothing ‘Releasing memory
-------------------------------------------------------------------------------------------------------

2)‘Checking for the existence of the file and entering some data into it
' If Not exists Create the Excel file /Work book and enter some data

Dim objExcel, objFso, FilePath
FilePath="D:\Alok\alok.xls"
Set objFso=CreateObject("Scripting.FileSystemObject")
Set objExcel=CreateObject("Excel.Application")

If objFso.FileExists(FilePath) Then
objExcel.Workbooks.Open (FilePath)
objExcel.Worksheets("Sheet1").Cells(1,1)="VB Script"
objExcel.ActiveWorkbook.Save
Else
objExcel.Workbooks.Add
objExcel.ActiveSheet.Cells(2,2)="VB Script"
objExcel.ActiveWorkbook.SaveAs (Filepath)
End If

objExcel.Quit 'To Quit the Excel Appliction
Set objExcel=Nothing
------------------------------------------------------------------------------------------------

3) 'Fetch Test Data directly from an Excel file and perform Data driven testing for Login Operation

Dim objExcel, objWorkbook, objWorksheet
'Create Excel application Object that can be used to perform operations on Excel Appliction
Set objExcel=CreateObject("Excel.Application")
'Create WorkBook Object using Excel application Object that can be used to perform operations on Excel Work Books
Set objWorkbook=objExcel.Workbooks.Open ("C:\Documents and Settings\Administrator\Desktop\input.xls")
'Create Work sheet object Using Work Book Object, that can be used to perform operations on Excel Sheets
Set objWorksheet=objWorkbook.Worksheets("Sheet1")
Rows_Count=objWorksheet.usedrange.rows.count

For i= 2 to Rows_Count Step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objWorksheet.Cells(i,"A")
Dialog("Login").WinEdit("Password:").Set objWorksheet.Cells(i,"B")
Wait 1
Dialog("Login").WinButton("OK").Click
Window("Flight Reservation").Close

Next
objExcel.Quit
Set objWorksheet=Nothing
Set objWorkbook=Nothing
Set objExcel=Nothing
-------------------------------------------------------------------------
4) 'Fetch Test Data directly from an Excel file and perform Data driven testing for Login Operation

'Export Test Results to the same file
Dim objExcel, objWorkbook, objWorksheet
'Create Excel application Object that can be used to perform operations on Excel Appliction
Set objExcel=CreateObject("Excel.Application")
'Create WorkBook Object using Excel application Object that can be used to perform operations on Excel Work Books
Set objWorkbook=objExcel.Workbooks.Open ("C:\Documents and Settings\Administrator\Desktop\input.xls")
'Create Work sheet object Using Work Book Object , that can be used to perform operations on Excel Sheets
Set objWorksheet=objWorkbook.Worksheets("Sheet1")
objWorksheet.Cells(1,3)="Results"
Rows_Count=objWorksheet.usedrange.rows.count

For i= 2 to Rows_Count Step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objWorksheet.Cells(i,"A")
Dialog("Login").WinEdit("Password:").Set objWorksheet.Cells(i,"B")
Wait 1
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(12) Then
Window("Flight Reservation").Close
objWorksheet.Cells(i,"C")="Login Successful"
Else
SystemUtil.CloseDescendentProcesses
objWorksheet.Cells(i,"C")="Login Filed"
End If

Next
objWorkbook.Save
objExcel.Quit
Set objWorksheet=Nothing
Set objWorkbook=Nothing
Set objExcel=Nothing

5) 'Fetch Test Data directly from an Excel file and perform Data driven testing for Login Operation

'Export Test Results & Error Messgae to the same file
Dim objExcel, objWorkbook, objWorksheet, rows_Count

Set objExcel=CreateObject("Excel.Application")
Set objWorkbook=objExcel.Workbooks.Open ("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set objWorksheet=objWorkbook.Worksheets(1)

objWorksheet.Cells(1,3)="Test Result"
objWorksheet.Cells(1,4)="Error Message"

rows_Count=objWorksheet.usedrange.rows.count

For i= 2 to rows_Count Step 1
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objWorksheet.Cells(i, 1)
Dialog("Login").WinEdit("Password:").Set objWorksheet.Cells(i, "B")
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(12) Then
Window("Flight Reservation").Close
objWorksheet.Cells(i, 3)="Login Successful"
Else
objWorksheet.Cells(i, 3)="Login Failed"
objWorksheet.Cells(i, 4)=Dialog("Login").Dialog("Flight Reservations").Static("Agent name must be at").GetROProperty ("text")
SystemUtil.CloseDescendentProcesses
End If
Next

objWorkbook.Save
objExcel.Quit
Set objWorksheet=Nothing
Set objWorkbook=Nothing
Set objExcel=Nothing
6)
Using While...Wend Loop
------------------------
Dim objExcel, objWorkbook, objWorksheet, rows_Count, i

Set objExcel=CreateObject("Excel.Application")
Set objWorkbook=objExcel.Workbooks.Open ("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set objWorksheet=objWorkbook.Worksheets(1)

objWorksheet.Cells(1,3)="Test Result"
objWorksheet.Cells(1,4)="Error Message"

rows_Count=objWorksheet.usedrange.rows.count
i= 2
While i<= rows_Count
SystemUtil.Run "C:\Program Files\HP\QuickTest Professional\samples\flight\app\flight4a.exe","","C:\Program Files\HP\QuickTest Professional\samples\flight\app\","open"
Dialog("Login").Activate
Dialog("Login").WinEdit("Agent Name:").Set objWorksheet.Cells(i, 1)
Dialog("Login").WinEdit("Password:").Set objWorksheet.Cells(i, "B")
Dialog("Login").WinButton("OK").Click

If Window("Flight Reservation").Exist(12) Then
Window("Flight Reservation").Close
objWorksheet.Cells(i, 3)="Login Successful"
Else
objWorksheet.Cells(i, 3)="Login Failed"
objWorksheet.Cells(i, 4)=Dialog("Login").Dialog("FlightReservations").Static("Agent name must be at").GetROProperty ("text")
SystemUtil.CloseDescendentProcesses
End If
i=i+1
Wend

objWorkbook.Save
objExcel.Quit
Set objWorksheet=Nothing
Set objWorkbook=Nothing
Set objExcel=Nothing

7) 'Capture Link names from Google home page and export to Excel file3rd sheet

Dim ObjExcel,ObjWorkbook,ObjWorksheet
Dim oLink,Links,myLink,i

Set ObjExcel=CreateObject("Excel.Application")

Set ObjWorkbook=ObjExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\input.xls")

Set ObjWorksheet=ObjWorkbook.Worksheets(3)
ObjWorksheet.Cells(1,1)="Link Names"
Set oLink=Description.Create

oLink("micclass").value="Link"

Set Links=Browser("title:=Google").Page("title:=Google").ChildObjects(oLink)

For i=0 to Links.Count-1 step 1

myLink=Links(i).GetRoProperty("text")
ObjWorksheet.Cells(i+2,1)=myLink
Next

ObjWorkbook.Save

ObjExcel.Quit

Set ObjWorksheet=Nothing

Set ObjWorkbook=Nothing

Set ObjExcel=Nothing
----------------------------------------------------------------------------------
8) 'Capture Button names from Login Dialog (Flight Reservation Application) and export to Excel file 3rd sheet

Dim ObjExcel,ObjWorkbook,ObjWorksheet
Dim oButton,Buttons,myButton,i

Set ObjExcel=CreateObject("Excel.Application")
Set ObjWorkbook=ObjExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set ObjWorksheet=ObjWorkbook.Worksheets(2)

ObjWorksheet.Cells(1,1)="Button Names"

Set oButton=Description.Create
oButton("Class Name").value="WinButton"
Set Buttons=Dialog("text:=Login").ChildObjects(oButton)

For i=0 to Buttons.Count-1 step 1
myButton=Buttons(i).GetRoProperty("text")
ObjWorksheet.Cells(i+2,1)=myButton
Next

ObjWorkbook.Save
ObjExcel.Quit
Set ObjWorksheet=Nothing
Set ObjWorkbook=Nothing
Set ObjExcel=Nothing
-----------------------------------------------------------------------------------
9) ' Read/capture order numbers and customer names from 1 - 10 orders in Flight Reservation window

' and export to excel file 2nd sheet
Dim objExcel, objWorkBook, objWorkSheet, ord, C_Name
Set objExcel = createobject("Excel.Application")
Set objWorkBook = objExcel.Workbooks.Open("C:\Documents and Settings\akm\Desktop\Sample.xls")
Set objWorkSheet = objWorkBook.Worksheets(2)
objWorkSheet.cells(1,1) = "Order No."
objWorkSheet.cells(1,2) = "C-Name"

For ord= 1 to 10 Step 1
Window("Flight Reservation").Activate
Window("Flight Reservation").WinButton("Button").Click
Window("Flight Reservation").Dialog("Open Order").WinCheckBox("Order No.").Set "ON"
Window("Flight Reservation").Dialog("Open Order").WinEdit("Edit").Set ord
Window("Flight Reservation").Dialog("Open Order").WinButton("OK").Click
Wait 1
C_Name = Window("Flight Reservation").WinEdit("Name:").GetROProperty("text")
objWorkSheet.cells(ord+1,1) = ord
objWorkSheet.cells(ord+1,2) =C_Name
Next

objWorkBook.Save
objExcel.Quit
Set objWorkSheet=Nothing
Set objWorkBook=Nothing
Set objExcel=Nothing

10) One to One Comparison and Exact match
----------------------------------------
'Capture Button names from Login Dialog (Flight Reservation Application) and Perform One to One Comparison and Exact match

Dim ObjExcel,ObjWorkbook,ObjWorksheet
Dim oButton,Buttons,myButton,i

Set ObjExcel=CreateObject("Excel.Application")
Set ObjWorkbook=ObjExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set ObjWorksheet=ObjWorkbook.Worksheets(2)

ObjWorksheet.Cells(1,2)="Buttons"

Set oButton=Description.Create
oButton("Class Name").value="WinButton"
Set Buttons=Dialog("text:=Login").ChildObjects(oButton)

For i=0 to Buttons.Count-1 step 1
myButton=Buttons(i).GetRoProperty("text")
ObjWorksheet.Cells(i+2, 2)=myButton
Next
rows_Count= ObjWorksheet.usedrange.rows.count
For j= 2 to rows_Count step 1
Expected=ObjWorksheet.Cells(j, 1)
Actual=ObjWorksheet.Cells(j, 2)

If Expected=Actual Then
ObjWorksheet.Cells(j, 3)="Pass"
Else
ObjWorksheet.Cells(j, 3)="Fail"
End If
Next

ObjWorkbook.Save
ObjExcel.Quit
Set ObjWorksheet=Nothing
Set ObjWorkbook=Nothing
Set ObjExcel=Nothing

11) One to One Textual Comparison
------------------------------
'Capture Button names from Login Dialog (Flight Reservation Application) and Perform and Perform One to One Textual Comparison

Dim ObjExcel,ObjWorkbook,ObjWorksheet
Dim oButton,Buttons,myButton,i

Set ObjExcel=CreateObject("Excel.Application")
Set ObjWorkbook=ObjExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set ObjWorksheet=ObjWorkbook.Worksheets(2)

ObjWorksheet.Cells(1,2)="Buttons"

Set oButton=Description.Create
oButton("Class Name").value="WinButton"
Set Buttons=Dialog("text:=Login").ChildObjects(oButton)

For i=0 to Buttons.Count-1 step 1
myButton=Buttons(i).GetRoProperty("text")
ObjWorksheet.Cells(i+2, 2)=myButton
Next
rows_Count= ObjWorksheet.usedrange.rows.count
For j= 2 to rows_Count step 1
Expected=ObjWorksheet.Cells(j, 1)
Actual=ObjWorksheet.Cells(j, 2)

If StrComp (Expected,Actual,1)=0 Then
ObjWorksheet.Cells(j, 3)="Pass"
Else
ObjWorksheet.Cells(j, 3)="Fail"
End If
Next

ObjWorkbook.Save
ObjExcel.Quit
Set ObjWorksheet=Nothing
Set ObjWorkbook=Nothing
Set ObjExcel=Nothing
--------------------------------------------------------------------------
12) Many to Many Comparison
-----------------------------------
'Capture Button names from Login Dialog (Flight Reservation Application) and Perform and Perform Many to Many Comparison

Dim ObjExcel,ObjWorkbook,ObjWorksheet
Dim oButton,Buttons,myButton,i

Set ObjExcel=CreateObject("Excel.Application")
Set ObjWorkbook=ObjExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set ObjWorksheet=ObjWorkbook.Worksheets(2)

ObjWorksheet.Cells(1,2)="Buttons"

Set oButton=Description.Create
oButton("Class Name").value="WinButton"
Set Buttons=Dialog("text:=Login").ChildObjects(oButton)

For i=0 to Buttons.Count-1 step 1
myButton=Buttons(i).GetRoProperty("text")
ObjWorksheet.Cells(i+2, 2)=myButton
Next
rows_Count= ObjWorksheet.usedrange.rows.count

For j= 2 to rows_Count step 1
Expected=ObjWorksheet.Cells(j, 1)

For k=2 to rows_Count step 1
Actual=ObjWorksheet.Cells(k, 2)

If Expected=Actual Then
Flag =1
Exit for
else
Flag= 0
End If
next

If Flag=1 Then
ObjWorksheet.Cells(j, 3)="Pass"
Else
ObjWorksheet.Cells(j, 3)="Fail"
End If
Next

ObjWorkbook.Save
ObjExcel.Quit
Set ObjWorksheet=Nothing
Set ObjWorkbook=Nothing
Set ObjExcel=Nothing

-------------------------------------------------------------------
13) Many to Many Textual Comparison

'Capture Button names from Login Dialog (Flight Reservation Application) and Perform and Perform Many to Many Textual Comparison

-----------------------------------
'Capture Button names from Google home page and export to Excel file 3rd sheet

Dim ObjExcel,ObjWorkbook,ObjWorksheet
Dim oButton,Buttons,myButton,i

Set ObjExcel=CreateObject("Excel.Application")
Set ObjWorkbook=ObjExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set ObjWorksheet=ObjWorkbook.Worksheets(2)

ObjWorksheet.Cells(1,2)="Buttons"

Set oButton=Description.Create
oButton("Class Name").value="WinButton"
Set Buttons=Dialog("text:=Login").ChildObjects(oButton)

For i=0 to Buttons.Count-1 step 1
myButton=Buttons(i).GetRoProperty("text")
ObjWorksheet.Cells(i+2, 2)=myButton
Next
rows_Count= ObjWorksheet.usedrange.rows.count

For j= 2 to rows_Count step 1
Expected=ObjWorksheet.Cells(j, 1)

For k=2 to rows_Count step 1
Actual=ObjWorksheet.Cells(k, 2)

If StrComp (Expected,Actual,1)= 0 Then
Flag =1
Exit for
else
Flag= 0
End If
next

If Flag=1 Then
ObjWorksheet.Cells(j, 3)="Pass"
Else
ObjWorksheet.Cells(j, 3)="Fail"
End If
Next

ObjWorkbook.Save
ObjExcel.Quit
Set ObjWorksheet=Nothing
Set ObjWorkbook=Nothing
Set ObjExcel=Nothing
---------------------------------------------------------------------------------------

14) 'Create Excel file and Rename 1st sheet as "Module", 2nd Sheet as "Test Case", 'and 3rd Sheet as "Test Step"
Dim objExcel
Set objExcel=CreateObject("Excel.Application")
objExcel.Visible=True
objExcel.Workbooks.Add
objExcel.Worksheets("Sheet1").Name="Module"
Wait 4
objExcel.Worksheets("Sheet2").Name="TestCase"
Wait 4
objExcel.Worksheets("Sheet3").Name="TestStep"

objExcel.ActiveWorkbook.SaveAs "C:\Documents and Settings\Administrator\Desktop\abcd.xls"

objExcel.Quit
Set objExcel=Nothing
-------------------------------------------------------------------------
15) 'Create an Excel file and add one more

Dim objExcel
Set objExcel=CreateObject("Excel.Application")
objExcel.Visible=True
objExcel.Workbooks.Add 'Creating Work Book
objExcel.Worksheets.Add 'Creating Work Sheet
Wait 4
objExcel.ActiveWorkbook.SaveAs "C:\Documents and Settings\Administrator\Desktop\abcde.xls"

objExcel.Quit
Set objExcel=Nothing
--------------------------------------------------------------------------------------
16) 'Capture Button names from Login Dialog (Flight Reservation Application) and perform Many to Many Complete Comparison

Capture Button names from Google home page and export to Excel file 3rd sheet

Dim ObjExcel,ObjWorkbook,ObjWorksheet
Dim oButton,Buttons,myButton,i

Set ObjExcel=CreateObject("Excel.Application")
Set ObjWorkbook=ObjExcel.Workbooks.Open("C:\Documents and Settings\Administrator\Desktop\input.xls")
Set ObjWorksheet=ObjWorkbook.Worksheets(2)

ObjWorksheet.Cells(1,2)="Buttons"

Set oButton=Description.Create
oButton("Class Name").value="WinButton"
Set Buttons=Dialog("text:=Login").ChildObjects(oButton)

For i=0 to Buttons.Count-1 step 1
myButton=Buttons(i).GetRoProperty("text")
ObjWorksheet.Cells(i+2, 2)=myButton
Next
rows_Count= ObjWorksheet.usedrange.rows.count

x =0

For j= 2 to rows_Count step 1
Expected=ObjWorksheet.Cells(j, 1)
flag = 0
For k=2 to rows_Count step 1
Actual=ObjWorksheet.Cells(k, 2)
If StrComp (Expected,Actual,1)= 0 Then
Flag =1
End If
x=x+1 ' increment the comparison count
next

If Flag=1 Then
ObjWorksheet.Cells(j, 3)="Pass"
Else
ObjWorksheet.Cells(j, 3)="Fail"
End If
msgbox x 'inner loop comparison values
Next
msgbox x ' Total number of comparisons

ObjWorkbook.Save
ObjExcel.Quit
Set ObjWorksheet=Nothing
Set ObjWorkbook=Nothing
Set ObjExcel=Nothing