Documentos de Académico
Documentos de Profesional
Documentos de Cultura
All rights reserved. No parts of this work may be reproduced in any form or by any means - graphic, electronic, or
mechanical, including photocopying, recording, taping, or information storage and retrieval systems - without the
written permission of the publisher.
Products that are referred to in this document may be either trademarks and/or registered trademarks of the
respective owners. The publisher and the author make no claim to these trademarks.
While every precaution has been taken in the preparation of this document, the publisher and the author assume no
responsibility for errors or omissions, or for damages resulting from the use of information contained in this
document or from the use of programs and source code that may accompany it. In no event shall the publisher and
the author be liable for any loss of profit or any other commercial damage caused or alleged to have been caused
directly or indirectly by this document.
Cover Designer Last but not least, thank you to all our families for their support and
Matt Kurvin patience while we wrote the book
Team Coordinator
Noel Rice
Production
Falafel Software Inc.
4 TestComplete Made Easy
Table of Contents
Foreword 9
Part I Introduction 11
1 Introduction
...................................................................................................................................
to TestComplete 11
2 Who Should
...................................................................................................................................
Read this Book 11
3 What Do...................................................................................................................................
You Need to Have Before You Read this Book? 12
4 What Do...................................................................................................................................
You Need to Know Before Reading this Book? 13
5 How the ...................................................................................................................................
Book is Organized 13
Part II AutomatedQA 17
1 History ................................................................................................................................... 17
2 Product ...................................................................................................................................
Offerings 17
5
6 TestComplete Made Easy
5 Summary
................................................................................................................................... 111
1 Objectives
................................................................................................................................... 164
2 ADO ................................................................................................................................... 164
3 BDE ................................................................................................................................... 166
4 Hands on
...................................................................................................................................
Lab: Query Database 166
5 Summary
................................................................................................................................... 174
7
8 TestComplete Made Easy
2 Installing
...................................................................................................................................
Remote Agent 239
3 Running
...................................................................................................................................
Remote Agent 239
4 Configuring
...................................................................................................................................
Remote Agent 241
5 Hands on Lab: Working with Remote Agent for HTTP Load
Testing................................................................................................................................... 243
6 Summary
................................................................................................................................... 247
Index 280
Foreword
It’s easy to get started with TestComplete, but to take full advantage of
everything that it has to offer you need not only to understand the built-in
functionality, but you also need a deep knowledge of your testing trade
and software development best practices. Anyone writing a book on
TestComplete had better have that kind of depth and experience. To be
honest, there just aren’t that many experts in this field that have such
experience and are also proficient and entertaining technical writers.
I
Introduction
Introduction 11
1 Introduction
1.1 Introduction to TestComplete
About TestComplete
Today automated testing plays a vital role in many software development projects. Automated
testing has long been thought critical for large software development organizations, but is often
considered to be too expensive and difficult to implement for smaller companies.
TestComplete offers systematic, automated, and structured testing, with superior support for
.NET, Java, Visual C++, Visual Basic, WPF (XAML), Delphi, C++Builder and web
applications. It is equally oriented for testing 32-bit and 64-bit applications. With TestComplete
you can also test PowerBuilder, FoxPro, Access and other applications.
TestComplete is the ultimate solution to perform nightly tests and to help you get reliable daily
builds of your software.
TestComplete tools and features let every member of your team, developers and non-developers,
no matter how technically savvy, contribute to your testing projects. Once you start using
TestComplete, you will be able to turn every test run into a key contribution to your overall
development efforts. TestComplete will keep your projects on schedule and on spec, the team
confident, and the work 100% productive.
With TestComplete you and your team can implement comprehensive software testing strategies,
“automating the non-automatable” for maximum return on investment:
“In my opinion, [TestComplete] is a must-have tool for any software developer who believes in
applying a rigorous testing methodology to his products. The ability to work with Visual C++,
Visual Basic, C++Builder, Delphi, Java and .NET applications means that you’re virtually
getting several tools in one, and the wide variety of scripting languages means you can work in
whatever language you’re most comfortable with. Even if you have no interest in automated
testing procedures, [TestComplete’s] fascinating ability to ‘automate the non-automatable’ is
sure to find a use on your desktop!” Dave Jewell, Delphi Magazine
· You have never used TestComplete and want to learn what it's all about.
· You have worked in a QA environment and want to learn the AutomatedQA approach using
TestComplete.
· You have used TestComplete and want to make your knowledge more comprehensive.
1.3 What Do You Need to Have Before You Read this Book?
This book was written for TestComplete 6.x.
Additional Requirements
Ø To test Java Open Applications, you must have one of the following Java virtual machines installed
on your computer:
o MSVM, build 3309 or later.
o Sun JDK (or JRE) v. 1.1.8 or later.
o BEA JRockit 5.0.
Ø To test .NET Open Applications, the Microsoft .NET Framework v. 1.0.3705 or later is required.
Ø To execute TestComplete tests from test projects created in Microsoft Visual Studio 2005, Microsoft
Visual Studio 2005 Team Suite ver. 8.0.50727.42 or later or Microsoft Visual Studio 2005 Team
Edition for Software Testers ver. 8.0.50727.42 or later are required.
Ø To install TestComplete’s Microsoft Visual Studio 2005 Team Foundation Integration package,
Microsoft Visual Studio 2005 Team Foundation Server Release is required.
Ø To perform load testing of web servers, Microsoft Windows 2000, Window XP, Windows Vista,
Windows Server 2003 or Windows NT with Service Pack 6.0 or later is required. Also, it is
recommended that your computer meets the following requirements:
· Minimal Configuration
The training is based on Windows platform testing. Although the product is capable of using 5 different
scripting languages, the source code for the book is written in VBScript and JScript.
This manual is used in TestComplete training classes along with lectures and hands-on lessons to give
students a rich learning environment. When this material is presented in the classroom, the format is
50% lectures and 50% hands-on labs. While a printed manual can't reproduce the experience of
listening to and working with a skilled trainer, it was written by those same trainers and we've done our
best to make the text in this book an acceptable stand-in for the lectures. The chapter text (or lectures if
we're lucky enough to be in class together) will provide you with the background knowledge on testing
and TestComplete. The hands-on labs will provide the practical skills required to handle real-world
testing scenarios and they are reproduced here exactly as they are presented in the classroom.
AutomatedQA
This section includes a brief history of how AutomatedQA came into being and its mission. The section
also includes a 1000 foot view of its award winning products TestComplete, Automated Build Studio,
AQtime, AQdevTeam, TestExecute and TestRecorder.
Project Items
This section provides an overview of all project item types with additional detail on the Win32 Tested
Application.
Test Log
This section discusses the test log and the types of messages available in TestComplete. We will learn
how to email the test log and also how to reduce the size of the test log.
Named Mappings
This section introduces Named Mappings and Aliases used to handle long object identifiers and to
provide identifiers with meaningful names.
Unit Testing
This section discusses unit testing, the types of unit test frameworks supported by TestComplete and
provides an example of using an NUnit unit test.
Manual Testing
This section looks at the structure of a TestComplete project and the parts that make up the various
testing functionality included in a project.
Data-Driven Testing
This section covers how the Data Driven Testing plug-in consumes common data types.
Event Handling
This section explains how to respond to events that occur during testing and explains how to handle
unexpected windows.
This section discusses how TestComplete represents web pages in the Object Browser, how to
navigate between web pages and how web checkpoints are used. This section also talks about
strategies for locating and testing dynamic HTML elements.
WebServices Testing
This section demonstrates how to test a web service, including how to import web service meta data,
calling simples methods, creating web service types and calling complex methods. This section also
explains how to create a web service checkpoint.
Remote Agent
Remote Agent is a tool that allows for the distribution of HTTP loads tests across a network of
computers. This section explains how to install, configure and run Remote Agent.
Distributed Testing
This section explains how tests are run on several computers at the same time.
User Forms
This section demonstrates how to create user forms and manipulate them using script
Best Practices
This section contains notes on best practices for testing in general and web pages in specific.
Cheat Sheet
Here you'll find a handy reference to TestComplete general keyboard shortcuts, shortcuts for Code
Completion, keyboard handling in the recorder, how to change global shortcuts and how to change
keyboard emulation.
II
AutomatedQA
AutomatedQA 17
2 AutomatedQA
2.1 History
AutomatedQA offers software products and services for development and quality assurance projects
worldwide. They create innovative, award-winning and affordable products for the entire software
development lifecycle including TestComplete for test automation and AQtime, a sophisticated
performance and memory profiler. AutomatedQA has an impressive list of customers ranging from huge
teams in the world's largest organizations to progressive one-developer shops. AutomatedQA was
founded in 1999 with headquarters in Las Vegas, Nevada, United States.
What does affordable and feature-rich mean? It means bang for the buck. It means that their solutions
tend to cost a fraction of their competitor's prices and offer more features. A good example is their
automated testing tool, TestComplete. Some of their competitors charge separately for different test
types like GUI testing, unit testing and load testing. TestComplete includes all supported testing types in
one product with more features, for considerably less. It’s this combination of affordability and features
that led Joel Spolsky, of joelonsoftware.com to write, “AutomatedQA's TestComplete is a great product
and just as capable as the market leader at less than one-tenth the price. Why would anybody pay $6000
per seat for test automation?”. -- Joel Spolsky
As a side note, AutomatedQA first customer ever in 1999, was no other that Falafel Software's QA
Master, Mr. Eric Holton.
AQtime
The latest version of AQtime, AQtime 5, includes dozens of productivity tools that help you easily isolate
and eliminate all performance issues and memory/resource leaks within your code by generating
comprehensive and detailed reports for your .NET and Windows applications. AQtime supports .NET
1.0, 1.1, 2.0, 3.0 applications and Windows 32- and 64-bit applications.
AQtime is built with one key objective - to help you completely understand how your programs perform
during execution. Using its integrated set of performance and debugging profilers, AQtime collects
crucial performance and memory/resource allocation information at runtime and delivers it to you both in
summarized and detailed forms, with all of the tools you need to begin the optimization process. This is
all done without modifying the application's source code!
With AQtime's intuitive and user-friendly interface and instrumentation in hand, you will quickly
know the exact speed, memory usage, and application usability issues in your programs. As you
optimize and improve your code, AQtime provides all the tools to compare and merge results so
that over time, an exact and accurate "picture" of your application's state takes shape:
· Monitor and report on all areas that could degrade your project’s performance and quality.
· Assess the thoroughness of your tests by using Coverage Profiling.
· Ensure that you make the right code improvements from day one.
· Helps drill down to the exact line of source code that is responsible for performance or memory
allocation inefficiencies.
unprecedented flexibility allows even inexperienced users to create complex visual macros which can
automate repetitive or day-to-day tasks with the single click of a button.
Even though the product name includes the word “build”, you can use Automated Build Studio
to automate any common or everyday tasks in your organization. Automated Build Studio
contains over 540 built-in operations that will help you:
· Compile applications
· Create installation packages
· Perform automated builds as scheduled tasks
· Get and put files from/into version control systems
· Label sources in version control systems
· Compile help files
· Create, modify and delete registry keys and INI file settings
· Copy and move files to a location (network drive, Web site, FTP server, etc.)
· Extract and pack files from/to ZIP and RAR archives
· Run automated test scripts and profilers
· Post bug reports to issue-tracking systems
· Send and receive e-mail, ICQ and newsgroup notifications
· Burn CDs and DVDs
· Register COM and .NET components
· Perform scripting operations in any of 3 scripting languages (VBScript, Jscript or DelphiScript) or
many other operations...
TestExecute
TestExecute allows you to execute scripts written with TestComplete and log test results on machines
that do not have TestComplete installed - using a simple, resource friendly command-line utility.
TestExecute gives QA departments the ability to test applications in real life user environments - such as
at customer sites - without the need to install TestComplete on the target machine.
TestRecorder
TestRecorder is a set of runtime libraries to be distributed with your 32-bit and 64-bit applications. Once
incorporated into your app, TestRecorder fully records end-user actions in the binary format. Later, the
recorded data can be converted with TestComplete to an easily readable script code in VBScript, Jscript,
DelphiScript, C++Script or C#Script. These scripts tell you exactly what a user was doing during
application execution - allowing you to accurately repeat the sequence of user actions via TestComplete
or TestExecute.
III
Overview of Testing and TestComplete
Overview of Testing and TestComplete 23
3.2 Terminology
First, let's define a few terms to help facilitate a discussion on testing:
Manual Testing
Manual Testing is where a tester methodically exercises the features of a product or product area without
the aid of test automation. The single greatest strength of manual testing is that it is truly real-world
testing, meaning that the tester can utilize the application under test the same way an end user would.
Through manual testing the tester can provide a wide variety of feedback about the application under
test not limited to simply reproducing bugs.
The major weakness of manual testing is that it is time consuming, tedious and requires extended
periods of very focused attention which can be very difficult to perform on a regular basis. Manual
testing tends to be quite error prone, leading to situations where consistently reproducing a bug can be
very difficult.
Functional Testing
Functional Testing focuses on interactions with an application's user interface (UI) via the mouse,
keyboard or other input device with particular attention to how the application visually responds to input.
The goal of Functional Testing is to methodically cover all of the various UI features exposed by an
application. Functional Testing should be highly organized and structured in a manner that allows for
additional tests to easily be incorporated as new features are added.
Unit Testing
Unit Testing is testing that focuses on smaller atomic portions of an application. Typically, Unit Testing
requires internal knowledge of how an application performs and seeks to test portions (objects, methods
and function) of an application in isolation. In many cases, applications have to be designed with Unit
Testing in mind in order for this type of testing to be truly effective. The benefit of unit testing is that it
tends to force application developers to write smaller more well defined routines with fewer
dependencies allowing for more highly specific tests to be developed.
Regression Testing
Regression Testing is process of executing tests in a repeatable manner and comparing the latest results
with previous test executions to ensure that the same outcome is achieved. Regression Testing is
extremely important and is the means of realizing the value of test automation. Repeatedly executing
tests over time allows you to verify the application is still performing in the manner in which it was
intended.
Distributed Testing
Distributed Testing is the act of farming different portions of a test out to separate machines for
execution. Distributed Testing is useful for simulating real world interactions on a networked application
such as a web site or web service and can exercise functionality designed to handle concurrent use of
application resources including, but not restricted to data.
Multi-Tier Explained
In software development there are typically three Tiers which are used to describe various aspects of an
application they are Client Tier, Middle Tier and Data Tier. These are each defined as:
Client - The user interface or presentation of an application and it's data which is typically covered
through Functional Testing.
Data Tier - The storage of an application's data which can be exercised by Functional Testing as well as
Unit Testing
Middle Tier - Refers to the portion of the application responsible for moving data back and forth between
the Client and the Data Tiers. The code that resides in this Tier can be tested from either the Client Tier
via Functional testing or through Unit Testing on the code in the Middle Tier itself. Keep in mind that
these are not strict rules as to which type of testing should be used but more illustrative how the different
types of testing can be used.
Now you might be thinking "huh? I haven't even started yet and I have to think about communicating my
results?" The answer is a resounding YES! Unfortunately, Quality Assurance and test automation
specifically, at least in the software world, tends to get a bad rap. Creating solid test automation that can
stand up over time and provide valuable ongoing feedback is a difficult task which leads a lot of people
(read management) to think time and effort spent working on automation is wasted.
To solve this problem you'll want to focus on getting your test results published quickly and consistently
to prove that you're efforts are worth the investment. TestComplete provides some facilities for
producing log output though you'll want to be sure and iron out your strategy from the start. For example,
you may want to setup a web server where you can publish results in fact, TestComplete supports
exporting log results to HTML which could be a good starting place.
TestComplete is rich with features that make test automation easier although like any development tool
it provides many different ways to solve the same problem. For example, TestComplete has a powerful
and indeed almost alluring, recorder making it easy to quickly create automated tests. While a test
recorder is a great tool, recorded tests tend to be more brittle than hand written tests because they
capture a single iteration at a given point in time and don't take into account unexpected events like an
error dialog popping up. The alternative is handwritten tests where you can methodically plan how the
test will react in unexpected circumstances. The down side of handwritten tests is they tend to take
longer to develop though over the long run they'll likely require less maintenance because of the
tendency to design the test more rigorously. That said, it's not a bad idea to start with a recorded script
and massage it into what amounts to a handwritten test.
· Run quickly - a smoke test should not last for hours but minutes and test the most crucial
functionality
· Fail quickly - as soon as a failure is detected in the smoke test should end and trigger a failure
notification
· Cover a broad range of functionality, focusing on breadth not depth
· Require minimal setup/configuration of the application under test
· Be setup to run against every build
· Adapt over time as the application under test evolves
· Serve as a model for new test automation
If you take the time to organize your smoke test to cover these goals you will undoubtedly save time and
resources over the long run. Your smoke test should serve as an model that embodies your "best
practices" from which your QA team can draw from for their own tests.
If you've never written a smoke test before, start small. In the beginning simply get the smoke test to
verify even a single piece of functionality consistently. Over time, work to increase its coverage but
remain focused on the quality of the test. It's unacceptable to have a smoke test that can't run
consistently and without problems.
The main benefit of a CI server is to reduce the amount of time it takes to execute your test automation
as well as ensure that it executes against every build. By setting up a CI server you can not only
alleviate your QA engineers from having to manually execute their tests but you'll quickly identify tests
that are unable to consistently run to completion and may require closer scrutiny. In addition, many CI
servers include a means of publishing test results providing for great visibility into the automation efforts.
3.6 Summary
To best leverage your investment in test automation it's important to plan your overall testing strategy.
Before diving in and unleashing the full power of TestComplete be sure to organize your communication
strategy. Make communicating your results an important part of judging the success of your efforts. Also,
treat your test development like any other software development project and use the tools available to
maintain the quality and integrity of your test code.
IV
TestComplete IDE Environment
TestComplete IDE Environment 29
TestComplete Menus
The TestComplete menus are no different from many Integrated Development Environments menus.
From the figures below, you can see the File, Edit, View, Script, Tools and Help menus.
TestComplete Toolbar
The TestComplete Toolbar is an easy way to get at TestComplete functionality or deeper menu
items with only one click. Saving files, adding new units, recording, playing back, debugging,
searching, formatting,etc...
The great thing about the toolbar is that it is customizable. So if you ever use a TestComplete
functionality often and you don't see it on the toolbar, add it by right clicking on the toolbar and
choose customize. Click on the Commands tab and drag any functionality you desire to anywhere
on the toolbar. Once you drag a command to the toolbar, the icon is persisted there permanently.
The TestComplete IDE as you might expect consists of several pluggable windows that facilitate project
management, code management, debugging, object browsing, main script and result logs workspaces.
The Project Workspace consists of two main windows, The Project Explorer and the Code
Explorer.
The Project Explorer will allow you to see all projects in a suite and all the specific Project Items
that are part of a specific Project. If you ever missed a Project Item from the Wizard at startup, you
can always right click on a Project in the Project Explorer and choose Add New Item, where you will
be presented with all TestComplete Project plug-ins to add to the project.
The Code Explorer on the other hand, is a different view into your code base that enables you to
navigate easily between functions in large files, rename functions, delete functions, sort functions by
name in the tree, etc...
The Object Browser is the most powerful part of TestComplete. It is where all the brains behind the
TestComplete muscle reside.
When you click on the Object Browser Window in TestComplete, the engine monitors all running
processes on your machine and extracts vital information about each process for display as you can see
below. You can filter the kind of processes you need to inspect or eliminate a category of processes by
right-clicking on the Object Tree below on the left and filter processes.
The Object Browser can also examine your system as a hardware unit and report on the CPU, CPU
count, amount of memory (RAM) on the machine, Operation system is use, and other useful information,
from a testing perspective.
The Process Tree Pane enables you to view all currently running processes on the machine and its
toolbar on top allows you to filter the processes from running application to system processes to chosen
testapps applications in your TestComplete project.
By Right clicking anywhere in the Object Tree Pane, the popup menu appears with options to refresh the
content of the tree, filter, terminate, copy to editor, sort and other useful functionality that we will discuss
later in this chapter.
From the Object Tree Pane, invoke the 3rd menu option from the top called Object Properties..., that
will invoke the following dialog when you need to quickly dissect a window on the screen.
As a Lab for this part of the chapter, let's use the Object Browser, Object Tree Pane and Object
Properties dialog to work with a Notepad window:
1. Open Notepad from the Windows directory or System32, depending of the version of Windows you
are running.
2. View the Object Browser in TestComplete to determine that the process of Notepad has been
detected by the Object Tree.
Notice that the process of Notepad is displaying three windows underneath the process and the
Properties of the process itself are displayed on the right.
The main Notepad window is actually the 3rd one down. The other two windows (IME and
MSCTFIME UI) are other non-visible windows in Notepad for language direction reasons like
Hebrew and Arabic, etc...
3. To make sure that the main window of Notepad is the 3rd one underneath the process, right click on
it and choose Highlight on the Screen.
Note: The Notepad application is brought to the front and the main window starts flashing with a
red rectangle around the main window several times.
4. Notice in the Properties window that most of the properties have a blue color arrow next to them. That
means these properties are READ-ONLY as far as the Object Browser is concerned.
5. One of the properties of that main window in Notepad is called "WndCaption" and it does not have
the blue arrow next to it. That means it can be written to from the Object Browser. This property is
actually the title of the window. Push the CTRL key and click inside of the edit area of the property.
6. Type "Welcome to TestComplete Training" and press [Enter].
7. Now go back to the Notepad application and view the title area of the application.
Don't worry, you did not change Notepad forever :) it is only for this session until it is shutdown and
started up again.
8. Now let's use the Finder tool to capture the Edit window in Notepad (The white area only with no
Notepad title or menus).
9. Invoke the Object Properties dialog from the popup menu of the Object Tree. Drag the Finder tool to
the white area in Notepad until you see a red rectangle around the edit portion only.
10.The Object Properties will automatically refresh and show all the properties TestComplete was able
to see from the Window object in memory.
The button pointed to by the number 1 above will allow you to highlight the window object in-place in
the Object Tree Pane as part of the Object Browser. This is a very handy button when your
application windows are numerous and have a deep hierarchy as is the case for Internet Explorer.
The button pointed to by number 2 above will allow you to highlight the object on the screen by
flashing it several times, similar to step 3 above.
From the previous sample with Notepad, you probably noticed that TestComplete recognized a lot of
properties of the main Notepad window as well as the Edit window. On the other hand, you probably
also noticed that the Fields and Events tab were blank. Even the Methods tab had only methods
pertaining to standard TestComplete functionality and actions.
Well, TestComplete will recognize objects and will go as deep as the application will allow it to. That
means, it is based on how the application was built, developed or compiled as to what TestComplete will
be able to see inside of it.
This brings up the topic of White Box Applications Vs. Black Box Applications.
TestComplete will be able to automatically see deeply inside .NET and Java application without any
changes to the application just because of the nature of metadata generation of .NET and Java
application which are easy to reflect. Reflection is the ability to retrieve internal objects, properties,
methods and events. So these are always called White Box Applications.
Some Applications are written in C, C++ or Delphi, these applications are mainly Black Box applications
but could be compiled in such a way to enable them to become White Box Applications. That would
require compiling with Debug information enabled and the inclusion of some TestComplete files into the
project to enable reflection of all program metadata.
While viewing the Object Browser, you will notice sometimes that a TestComplete icon will show next to
a specific process. That sign identifies the process as "OPEN" and means TestComplete can reflect its
content and get as much Runtime Type Information as possible.
In this sample, I used Visual Studio 2008 to generate a very simple C# based Windows application
that adds two numbers together
In case you don't have Visual Studio, the executable is available through the book download as
"TCDotNetApp.exe".
Notice that TestComplete automatically figured out that we are dealing with a .NET application so it
started using the built in "WINFORMSOBJECT" identifier to make it easier to reach all .NET
methods, fields, events and properties associated with the application.
At this point, if we had a function in the TCDotNetApp.exe called "Hello" that was never called from
the User Interface, it will still show up in the Methods tab. We would be able to call it directly from
the script and it will be visible to TestComplete via reflection.
Note: TestComplete has many built in recognition objects for Delphi VCL objects, Java Swing
objects, XAML WPF objects and others...
4.3.3 Editor
4.3.3.1 Code Completion
The Code Editor in TestComplete is easy to use and productive to get the job done.
One of the first features you will discover and love in the TestComplete Editor is the Code Completion
feature. I am not sure how we used to write code before this feature was introduced in major
development tools and in TestComplete.
Instead of having prior knowledge of the objects you need to deal with in TestComplete or have access
to the Help files, it is simple enough to let TestComplete do the job for you by entering the name of an
object and placing a "." a period after the object. That will invoke the Code Completion window with all
properties, methods and events available for that object. Sometimes you even have the need to invoke
the Code Completion window in the middle of a statement. That is possible using the handy keyboard
shortcut CTRL-SPACE.
Another great feature of the TestComplete Editor is the Parameter Completion feature. For
example, when you need to know the count and type of a parameter that TestComplete recognizes,
you can always open a parenthesis and key in CTRL-SHIFT-SPACE to bring up the Parameter
completion window:
4.3.3.2 Bookmarks
Another great feature of the editor in TestComplete is the ability to place bookmarks in script units
opened in the IDE and be able to jump between them by a simple keystroke. You can set a bookmark by
having the cursor on that line and pressing CTRL - SHIFT - and a number between 1 and 9.
In the figure above, please notice that the bookmarks are set on lines 5,15 and 18 (see the yellow
glyph in the gutter). Also, the Bookmarks window at the bottom of the editor will list all set
bookmarks with their numbers, their unit names and their line numbers. To jump to a specific
bookmark at any time, press CTRL - 0 to 9 (without the SHIFT). To delete a bookmark, delete from
the bookmark window or press CTRL-SHIFT- 0 to 9 again while the cursor is on the bookmark.
From Tools | Options, you can get to the Editor options under Panels | Code Editor:
Under Display, you have the choice to change the Text specifications, background colors and
margin, gutter styles and capacity and also whether you want to show line numbers or not.
Another very useful feature of the editor in TestComplete is the ability to set Code Templates.
Every Scripting language has it own templates. Above you will see that I added a new Template
called TCTraining that contains a function name "test" with a comment in it. The script itself can be
anything that you expect to use a lot in your testing. Notice also the little pipe "|" sign inside the
brackets. The pipes indicates the position of the cursor in the code after the template has been
inserted.
Now lets go back to the editor and try to enter this template:
1. Choose an empty are between two function and press CTRL - J.
The following code template helper will appear:
2. Choose the TCTraining Template from the list and press Enter.
The code is inserted in the script unit and the cursor is blinking right before the comment starts.
4.3.3.4 Debugging
4.3.3.4.1 Breakpoints
The Debugger capabilities in the TestComplete's Editor are very helpful in finding script errors, flow
problems and also to evaluate the values of local and global variables.
The Breakpoints window in TestComplete is very easy to use. You can set breakpoints in your
editor by clicking in the gutter next to the line you want to set a breakpoint on or by pressing F5
while the cursor is on that line.
In the Breakpoints window you can:
· Enable or disable a specific breakpoint. That is better than deleting them and reentering them all
over based on different debug sessions.
· View the Location of the unit name it resides in and also the line number of where it resides.
· Include a description to explain the goal behind using the breakpoint.
· Finally, you have two powerful features in the breakpoints window which are Pass Count and
Condition. If you are debugging a "For Loop" that goes on for 1000 iterations, knowing that it will
fail some time after 900 times, it would be wise to place a Pass Count of 900 on the breakpoint
instead of having to step over the breakpoint 900 times. When the pass count is not known but a
condition has to be met, the Condition property can be set (e.g: x > 100).
The Call Stack window is very helpful when your scripts get called one from the other in a long chain of
execution. During a break in execution, the Call Stack window will show the order of execution for the
calling functions to get to that point of execution. The figure below shows the Call Stack at a break in
execution. Usually that is good information for pinpointing the offending procedure. Unfortunately, in
many cases "X" does not mark the spot like an Indiana Jones' movie, so the problem you are trying to
figure out has already manifested itself way before the break in execution occurred. These are tougher
bugs to figure out.
4.3.3.4.3 Locals
The Locals window is an easy and fast way to monitor the value of local variable inside of a specific
function. Like in the figure below, we created 2 local variables, "myString" and "myNumber", and
assigned specific values to both. To view their values, you only need to open the Locals window and
they will be there as long as you are breaking inside of the function that contains them.
So how do you view values of variables that are not local to a function? That is the functionality of the
Watch List.
Notice in the screenshot below that the Global variable "myGlobal" did not show up in the locals window.
This is correct, as the myGlobal variable is not a local of that function.
To evaluate the myGlobal variable, go to the Watch List window and add a new item by right-
clicking in the window.
The output in the Watch List window will allow you to monitor the value of that variable during the
life of the execution session.
You can also use the Evaluate command available from the debug menu item in the editor:
4.4 Summary
In this chapter:
V
Projects and Suites
Projects and Suites 59
To create a new project select File | New | Project... and you will be presented with the Create New
Project dialog:
The Create New Project dialog presents you with a number of pre-configured Project Templates that are
geared towards specific types of testing. The templates are:
· General Purpose Test Project - useful for a wide variety of test scenarios
After creating a new project you can view all of its Project Items and sub items from the Project Explorer.
Projects
Projects can contain the following:
Both Project Suites and Projects provide a logical view of the files and folders that make up the
project. When removing nodes from the Project Explorer you are only removing them from this logical
view. The actual files and folders are not deleted from disk and may be added back to the project using
the right-click context menu and selecting Add | Existing Item...
Project Items
Project Items make up the specific types of testing functionality or assist in performing various test
operations. TestComplete includes a large collection of Project Items covering a wide variety of test
functionality. You can easily add and remove Project Items using the right-click menu on the Project
node of the Project Explorer.
Project Templates
Initially, accepting the defaults on this dialog will be the preferred choice until your familiar enough with
the available Project Items and can identify the ones you use most frequently at which point you can
create a Project Template. To define a new template select the Project Items you use most frequently
and click the Save As... button to create a new Project Template that will be available on the Create
New Project dialog.
2. On the Create New Project dialog from the list of Templates select the [All Items] template
3. Click the Unselect All button at the bottom of the Project Items checkbox
- Name Mapping
- Stores
5. In the left hand column on the dialog click Win32 Tested Applications
6. At the bottom of the Items list click the Add button to add a specific Windows application to test
against
7. On the Create New Item dialog fill in the name of your application and click Next
8. In the Tested application edit box type the complete filename including path to the Windows
application you wish to test or use the ellipsis (...) button to select the application
10. In the left hand column of the dialog click Select Project Items
12. On the Save Template dialog enter a Template Name and Description and click OK to create a
new project template that you can reuse
3. On the New Project Wizard click the Finish button, accepting the defaults
5.5 Summary
In this chapter we covered the structure of a TestComplete project and the parts that make up the
various testing functionality included in a project. You should be familiar with how to construct a Project
Template for use across your organization for greater consistency and easy of use when creating new
test projects.
VI
Project Items
Project Items 67
6 Project Items
6.1 Objectives
This section provides an overview of all project item types with additional detail on the Win32 Tested
Application.
· ActiveX - This project item allows you to load an ActiveX object in TestComplete's memory space
and use that object in your tests. For example you could use the Microsoft ADO Data Control to
work with databases.
· Events - This project item is used to hook to TestComplete events (and those of other application,
such as ActiveX controls). This item is not required but is highly recommended.
· HTTP Load Testing - Necessary for the creation of a load on a web server using TestComplete.
· Low-Level Procedure Collection - A virtual folder for holding low-level (screen coordinate based
tests) procedures.
· Manual Test - A virtual folder for holding manual tests.
· Name Mapping - Used to map the name of an object to a shorter name (aliasing).
· User Forms - A virtual folder for holding User Forms (Forms presented to the user during the test
run, such a progress dialog, etc).
· Web Services - A virtual folder for holding connection, methods and type of web services
(Information from the WSDL file).
· Win32 Tested Application - Holds information for managing the Application(s) under test.
· Launch - If checked, this application will be run if TestedApps.RunAll command is used (either from
script or context menu).
· Name - Is the name that TestComplete uses to refer to the tested application (must be a name that
the scripting language can handle).
· File Name - Is the name of the application on the disk.
· Count - This is the number of instances of the application that TestComplete will launch. If the
application is already running TestComplete will post a warning message in the Test Log.
· File Path - By default, File Path is the relative path to the file name from the TestComplete project.
· Run Mode - How the application is launched.
· Parameters - Allows parameters to be set using the ellipses button.
Run Mode
· Simple - Launches the application under the same user account as TestComplete. Parameters can
be passed in Simple mode.
· RunAs - Launches the application under the user account specified by the parameters dialog.
· Debug - Launches the application under the same user account as TestComplete, then
TestComplete attaches to the application as a "debugger". The stack trace of any exception that
occurs in the application while the test(s) are being run will be recorded in the TestLog. This option
requires debug information in the application under test.
· Profile - Launches the application inside of AQTime using the profile (or AQTime project) specified
in the parameters dialog. For example code coverage profiling could be used to see how much of
the code is being tested by your automated tests.
6.3 Summary
In this section we had a brief overview of the project items of TestComplete. We also looked at Win32
Tested Application project item in more detail.
VII
Test Log
72 TestComplete Made Easy
7 Test Log
7.1 Objective
This section discusses the test log and the types of messages available in TestComplete. We will learn
how to email the test log and also how to reduce the size of the test log. In this section you will:
Log Tree
This area will have a node for each Test Item level used to run the test. In the image above, for
example, a project suite was run. The project suite is the top (root) node and each project is represented
by the child of the project suite. The statuses of child items in the tree bubble up to the parent items. In
the screenshot above you can see that errors flagged in child level items (the red X indicates the error
status) have bubbled up to the project suite node.
The context menu for the Log Tree contains menu items to handle the log output including Export to IE,
Send Email and the ability to view closed Log Panels.
Script Log
This area contains messages coming from both TestComplete and the script code. The are six different
types of messages:
· Message - Can come from TestComplete or from the script code (Log.Message), will not cause the
test to fail.
· Warning - Can come from TestComplete or from the script code (Log.Warning), not necessary a
failure for the test but could be an indicator for why a test failed.
· Error - Can come from TestComplete or from the script code (Log.Error), this indicates a failure for
the test.
· Events - Usually comes from TestComplete but can come from the script as well (Log.Event), does
not cause the test to fail. TestComplete generates an event for every mouse-click or keyboard entry
in the test.
· Image - Usually comes from script code (Log.Picture) but TestComplete can generate as well
(Region Checkpoints).
· File - There are two types of File log items. Log.File, will copy the file into the directory holding the
log XML file and creates a hyperlink to the file. Log.Link just creates a hyperlink to the file without
copying the file.
The script log area may have a hierarchical structure via creating and pushing log folders onto the log (
Log.AppendFolder, Log.CreateFolder/Log.PushLogFolder, Log.PopLogFolder). All messages by
default go into the last pushed log folder (i.e., the top of the stack).
7.4 LockEvents
With any long running test, the test result log will be filled with hundreds if not thousands of events.
Most of the time, the tester is not interested in events unless there is a problem in the test run.
TestComplete can eliminate events unless an error occurs. By adding Log.LockEvents to the script
code, no events will be placed into the test log unless an error occurs. By default the last 20 events are
logged, but this can be changed by adding a parameter to the Log.LockEvents command.
7.5 Summary
In this section we learned about the test log and the different type of messages available in
TestComplete. We learned how to email the test log and also how to reduce the size of the test log.
VIII
Named Mappings
Named Mappings 77
8 Named Mappings
8.1 Objectives
This section introduces Named Mappings and Aliases used to handle long object identifiers and to
provide identifiers with meaningful names. In this section you will learn about:
· Named Mapping.
· Aliases and how they are different from Name Mapping
· How TestComplete uses Alias and Name Mapping.
Sys.Process("Hello").Panel1.Panel2.Container1.Container2.button1
Clearly there are numerous issues with this identifier, its long and awkward not to mention we have no
clue about the purpose or identity of "Container1", "Container2" or "button1". Named Mappings allow
you to rename Panel1, Panel2, Container1, Container2 and button1 to useful names like MyPanel,
myInsidePanel, myTabs, myPages and btnSubmit. The issue here is that you still need to type:
NameMappings.Sys.Process("Hello").MyPanel.myInsidePanel.myTabs.myPages.btnSubmit
TestComplete lets you create an Alias to represent this long string. If you create the Alias "btnSubmit",
you only need to type:
Aliases.btnSubmit
Consider the AutomatedQA website Products link at the top of the page:
The standard full name for this HTML element is: Sys.Process("iexplore").Page("http://www.
automatedqa.com/").Panel(0).Panel(0).Link(1).
This does not tell anyone reading the script what HTML element the code is working with. There are a
· Select the element in the Object Browser or Object Properties Window, and right-click for the
context menu and select "Map the Object Name..."
· Use the Map Object from Screen ( ) button from the Tools toolbar.
1. Click the Map Object from Screen button to displays the Map Object dialog.
2. Use the finder tool ( ) to select the Products link and push the OK button.
3. If the NameMapping project item is not in the project, TestComplete will ask if you want to add the
NameMapping project item.
· In the caption of the Object Name Mapping dialog, there is an indicator that shows how many
items need to be mapped in order to map the selected item.
· The standard TestComplete name for the object is shown just below the caption.
· The Selected Properties is used by TestComplete to find the on-screen object.
· The properties that are selected for a given on-screen object are configured using the Templates
button.
· Any property that is listed in Selected Properties or Available Properties can be added or
removed.
· The OK button will add the object to the NameMapping project item and the Aliases part of the
NameMapping project item.
· The Skip button will add the object to the Mapped Object part but not into the Aliases part of the
NameMapping project item.
9. Aliases are best explained by example, we are going press the Skip button for both the Sys object...
12.Press the Skip button for the Panel Objects (Skip two times).
13.On the second Panel object, TestComplete will say the it does not have enough information to
make this panel unique in the NameMapping project Item. Although, TestComplete can work with
non-unique objects, it is more reliable to have the object be unique.
19.The NameMapping project item editor with all nodes expanded now looks like:
In script code, the Product link can be referred to by the following code:
Sys.Process("iexplore").Page("http://www.automatedqa.com/").Panel(0).Panel(0).Link(1)
or
NameMapping.Sys.iexplore1.HomePage.Panel_0_.Panel_0_.ProductLink
or
Aliases.HomePage.ProductLink
In this way, Aliases allow you to ignore on-screen objects that were used for design but are not
necessary to the test automation process.
In the NameMapping project item editor, highlighting is done by selecting Highlight on Screen
from the context menu (right-clicking).
· Mapped Name - lets you define the name for an on screen object
· Selected Properties - the properties that are used to define this on screen object for name
mapping.
· Available Properties - additional properties that can be use to help refine the name mapping.
· Template Name - which template that TestComplete used to define the Selected Properties
initially.
· Select - if the on screen object matches one than one possible template, this button allows you to
choose which template to use.
· OK - Add the selected object to both the Mapped Objects and the Aliases sections of the
NameMapping project item.
· Cancel - Cancel the mapping at this point (all items mapped before will still be mapped).
8.6 Summary
We learned about what name mapping is and what it is used for. The difference between Aliases and
Name Mapping was explained. And we learned how to map an object from the screen.
IX
Unit Testing
Unit Testing 91
9 Unit Testing
9.1 Objectives
This section discusses unit testing, the types of unit test frameworks supported by TestComplete and
provides an example of using an NUnit unit test. In this section you will:
· Management gets a single report that includes both unit and automated tests.
· Provides an easy way for Quality Assurance to run unit tests (in addition to Developers running unit
tests).
· Can make it possible to run unit tests as part of the build process.
TestComplete supports five different types of Unit Testing:
· DUnit - A unit test framework for Delphi Applications, require that the test application be compiled as
open and include the tcDUnitSupport.pas file.
· JUnit - A de-facto standard unit test framework for Java Applications.
· MSTest - A unit test framework designed by Microsoft for unit testing .NET applications, comes with
Visual Studio 2008 and Visual Studio 2005 Team Edition.
· NUnit - An open-source unit test framework based on JUnit, used for unit testing .NET applications.
· TCUnitTest - A unit test frame work that allows unit testing of any open application.
Some of the unit test frameworks require that TestComplete know where the test runner application is
located on the test machine. The information can be entered in the Options Dialog (Tool | Options
from the main menu). From the Options Dialog select Engines | Unit Testing.
3. Click the ellipses button for the Assembly file name. Add the Assembly that holds the NUnit tests.
4. Push the OK button. This will open the NUnit editor in TestComplete.
The screenshots below show sample output and logging for the test run.
Most of the work for Test Cases in the Unit Test is done by the developer in the Application.
9.5 Summary
We learned about the types of unit test frameworks supported by TestComplete and how to use an NUnit
unit test.
X
Manual Testing
Manual Testing 99
10 Manual Testing
10.1 Objectives
This section discusses TestComplete's Manual Testing features, how to construct a simple manual test
using one of the provided sample applications and how to interact with manual tests from scripts.
In this section you'll learn:
· What a Manual Test is
· How to setup a Manual Test Project
· How to create a Manual Test
· How to use script within a Manual Test
1. From the main menu select File | New | New Project... which will display the Create New Project
dialog
3. On the Project Wizard dialog click the Unselect All button then under Project Items check Manual
Test and Win32 Tested Applications items
3. On the Project Wizard dialog click Unselect All and then check Manual Test and Win32 Tested
Application
4. Click Finish
4. Change Test caption to "Manual Test" and Test description to "Hands on Lab"
5. Under Test instructions type "Orders application must be running to complete this test"
6. Under Test Steps right-click and select Preview Step Dialog... (click Yes on the prompt to save the
dialog)
4. Add another step using the Add Step button and set the caption to "Add Order and Verify
Quantity"
1. In the Project Explorer right click ManualTest1 and select Run ManualTest1
3. Click Fail
7. Click Success
9. Click Continue
6. With the cursor at the end of TestedApps type a period "." to invoke the Code Complete again and
select Orders
7. Type another period and select Run
8. Press Return to add a new blank line below TestedApps.Orders.Run()
9. Press Ctrl-Space to display the Code Completion window
10.Select ManualTest1
11. Type "." and select Start
12. Press Return to add a new line below ManualTest1.Start
13. Press Ctrl-Space to display the Code Completion window
14. Select TestedApps
15. Type a period "." and select TerminateAll
3. In the Workspace under Available Events expand the Manual Testing Events node
4. Double click the OnBeforeStep event to add the event to your test
5. Under Events to Handle scroll the list down and locate the Manual Testing Events node
6. Click on the OnBeforeStep item then click the New button
7. Click OK on the New Routine dialog to add a new function to the Unit1 test script
8. In your Unit1 script file add a new blank like below the function declaration and type 'BuiltIn.
ShowMessage("Hi from script")'
9. Run the Project and click the Begin Test button. Notice the ShowMessage dialog appears:
10.5 Summary
In this section, we learned about TestComplete's Manual Testing features and constructed a simple
manual test using one of the provided sample applications. We also illustrated how you can interact with
manual tests from scripts.
XI
Basic Record and Playback
Basic Record and Playback 113
11.2 Overview
TestComplete has rich Record/Playback functionality allowing you to quickly record new test scripts.
TestComplete has several options that allow you to control how recording is performed. To view/change
these options select Tools | Options... and click the Engines folder and select Recording. You should see
the following options:
Capture Screen
Start Recording
Stop Recording
Pause Recording
Record Low Level Procedure (screen coordinates)
Record Script
More Details
Clicking the More Details button will expand the toolbar such that it displays Parent and Object name
data for the item underneath the mouse cursor.
Starting a Recording
To start a recording you must have a project loaded. You can load an existing project or start a new
project. Once you have a project loaded there are two ways to begin a new recording:
The Add Text to Script toolbar button allows you to insert either script or comments into the routine
that's currently being recorded. Clicking this button displays the Add Text to Script dialog:
Notice there is a checkbox at the bottom that allows you to indicate that the text is to be inserted as a
comment. There is also a Pick Object... button that allows you to insert a line of code that references a
specific onscreen object.
The recording toolbar has several buttons (see circled buttons below) that allow you to control the type of
recording being performed.
11.3.3 Pausing
TestComplete allows you to pause in the middle of a recording by clicking on the Pause button.
Pausing a test allows you to manipulate the application under test or change the environment without
recording any of those actions into the script. To resume a paused test click the Start Recording
button.
11.3.4 Stopping
To stop a recording click the Stop button. Clicking the Stop button will close the Recording toolbar
and restore the TestComplete main window leaving you in the Code Editor on the newly recorded script.
4. Select Run...
7. Click the Stop button on the recording toolbar to end the recording
11.5 Summary
In this section you learned how to perform basic record and playback tasks. We discussed the
functionality available on the toolbar including how to record various types of activity.
XII
Low Level Procedure
120 TestComplete Made Easy
12.2 Recording
The reason you want to use the Low Level Procedure feature in TestComplete is when the need arises
for recording specific mouse or keyboard operations on the screen for playback that are not
automatically recorded during a regular recording session.
For example, if TestComplete would record every mouse and keyboard operation automatically during
each recording session, we would have ended up with thousands of lines of script identifying the mouse
movement coordinates and clicks, while in most cases these are not necessary.
On the other hand, if you are trying to Paint in a program like MS Paint or trigger a Hover event inside of
Internet Explorer or FireFox, it is very much necessary that the recorder brings in the valuable mouse
and keyboard coordinates, clicks and keystrokes.
2. Make sure to enable Low Level Procedure Collection in the Project Wizard. If you forget, no
worries. You will still be able to add it to the project after the fact using the Add New Item menu of the
project in the Project Explorer.
3. When you start a recording session in TestComplete, you are presented with the recording tool bar
shown below. On the recording tool bar are two buttons that enable Low Level Procedure recording:
· The Screen Coordinates based button, which automatically set the coordinates for the recording as
(0,0) to be the top most left of the screen.
· The Window Coordinates based button, which sets the (0,0) coordinates starting from top most left
window under recording.
Tip: For a smoother playback and easier implementation between different resolutions on the
screen, we recommend the "Window Coordinates" button to be used.
9. Upon completion of your masterpiece, stop the recorder from the TestComplete recording toolbar.
10.Notice that TestComplete did not record any of the clicks on the MS Paint application, but added one
line of code to function Test1 to execute the collection of mouse movements and clicks collected
during the recorded session.
11.TestComplete collected all the mouse movement and clicks from the recorded session into an
LLCollection item in the project called "MSPaintCollection" (see above).
13.Notice the 900 + entries that were added to the collection to record all the mouse movement and
clicks.
14.Each record contains the mouse operation (down, up, move), the number of the operation, the event
name itself, the parameters of the mouse at that time (X & Y coordinates) and finally the delay in
milliseconds between operations.
15.The nice thing about this workspace area is that you are able to modify 1 or a bunch of these 900
records at will. You can reduce the amount of time between operations, delete meaningless mouse
movements that are not needed or event change the mouse coordinates on the screen after the fact.
You can now try to playback the recording by running the routine. What happened? Are you surprised?
Well, you probably saw the mouse moving on top of the TestComplete Editor in a pattern exactly as you
expected would happen in MS Paint. That is because nothing caused the MS Paint application to come
to the front or be activated.
To fix that issue for your script, always activate the window that needs to be focused and top-most
before running your low level procedures.
[JScript]
function Test1()
{
Sys.Process("MSPAINT").Window("MSPaintApp", "*").Activate();
LLCollection1.MSPaintCollection.Execute(
Sys.Process("MSPAINT").Window("MSPaintApp", "*"));
}
12.4 Summary
In this section we covered how and when to use a Low Level Procedure, recording choices, editing a
recording and used the Low Level procedure workspace to change coordinates, delays and events. We
also fixed a situation where the testing environment did not work as first expected.
XIII
Stores and Checkpoints
Stores and Checkpoints 129
6. Name the picture "Logo" and click OK in the "Create Region Checkpoint" dialog.
7. Copy the code into a method in TestComplete.
[VBScript]
Sub RegionCompareExample
If (Not Regions.Compare("Logo", Sys.Process("iexplore"). _
Page("http://www.activefocus.net/").Table(0).Cell(1, 0). _
Link(0).Image("nav_r1_c1"), False, False, True, 0)) Then
Call Log.Error("The regions are not identical.")
End If
End Sub
[JScript]
function RegionCompareExample()
{
if(!Regions.Compare("Logo", Sys.Process("iexplore").
Page("http://www.activefocus.net/").Table(0).
Cell(1, 0).Link(0).Image("nav_r1_c1"), false, false, true, 0))
Log.Error("The regions are not identical.");
}
12.Run the method again. There will be an error in the test log.
· The first picture in the log is the expected image (the one stored in the Region project item).
· The second picture in the log is the actual image.
· The third picture in the log (the one shown) is the difference between the two images (shown in red
pixels).
[JScript]
function PictureCompareExample()
{
if (!Sys.Process("iexplore").
Page("http://www.activefocus.net/").Table(0).
Cell(1, 0).Link(0).Image("nav_r1_c1").Picture().
Compare(Regions.GetPicture("Logo")))
{
Log.Error("The OnScreen Object is different")
}
}
3. Select two files to compare. You can find them either on disk or using the "Files" Project Item.
4. If you know the files are different and want to compare them, click the "Calculator" button next to the
Hash value edit box.
5. Press the OK button.
6. Copy the code to a new method.
[VBScript]
Sub FileCompareExample
If (Not Files.Compare("Sample1.txt", "Sample2.txt", 0, True)) Then
Call Log.Error("The files are not identical.")
End If
End Sub
[JScript]
function FileCompareExample()
{
[XML (Test.XML)]
<?xml version="1.0" standalone="yes" ?>
<Contacts>
<Contact>
<Name>Eric</Name>
<Company>Falafel</Company>
<Phone>888 GOT-FALAFEL</Phone>
</Contact>
<Contact>
<Name>Lino</Name>
<Company>Falafel</Company>
<Phone>888 GOT-FALAFEL</Phone>
</Contact>
<Contact>
<Name>Drew</Name>
<Company>AutomatedQA</Company>
<Phone>(978) 236-7900</Phone>
</Contact>
<Contact>
<Name>Derek</Name>
<Company>AutomatedQA</Company>
<Phone>(978) 236-7900</Phone>
</Contact>
<Contact>
<Name>Test</Name>
<Company>Test</Company>
</Contact>
</Contacts>
If there are known difference between files, you can still compare the files by using a hash value. To
compare these two files, the code would look like the example below:
Caution: The order that the files are compared makes a difference in the calculated Hash Value.
For example, consider the two xml files below. The hash value from TestComplete if "Contacts.
XML" is the first file in the comparison is 1812515919, if "Test.XML" is the first file the hash value
is 1883158225. So the order of the comparison makes a difference in what the final hash value
used in the Compare() function is.
[VBScript]
Files.Compare("Contacts.XML","Test.XML",1812515919,True)
[JScript]
Files.Compare("Contacts.XML","Test.XML",1812515919,true)
· Depending on the type of OnScreen object select, TestComplete will select certain properties for you
for comparison. Any of the unselected properties can be added for comparison.
[VBScript]
Sub ObjectCompareExample
If (Not Objects.Compare(Sys.Process("iexplore").
[JScript]
function ObjectCompareExample()
{
if(!Objects.Compare(Sys.Process("iexplore").
Page("http://www.activefocus.net/").Panel(0), "Panel", true))
Log.Error("The objects are not identical.");
}
· TestComplete will report the difference on the first object found with difference only.
Comparing Files
1. Create a new project with Events, Script, Stores, and TestedApps Project Items.
2. Add the "StoresSampleProgram" to the TestedApps.
3. Add the "Contacts.XML" to the "Files" Project Item (Copy to Stores).
4. Click the Record button in TestComplete.
5. Run the "StoresSampleProgram"
6. Open "Contacts.XML" in the StoresSampleProgram" (File | Open...)
7. Save the file as "Test.XML" in the StoresSampleProgram (File | Save)
8. Click "Create File Checkpoint" in the recording toolbar.
9. Select "Contacts.XML" as the first file.
10.Select "Test.XML" as the second file.
11.Press the OK button.
w1.Close
End Sub
[JScript]
function Test1()
{
var p1;
var w1;
var w2;
var w3;
TestedApps.StoresSampleProgram.Run();
p1 = Sys.Process("StoresSampleProgram");
w1 = p1.Form1;
w1.StripMainMenu.Click("File|Open...");
w2 = p1.Window("#32770", "Open Contacts XML");
w2.Window("SHELLDLL_DefView").Window("SysListView32", "FolderView").
ClickItem("Contacts.xml", 0);
w2.Window("Button", "&Open").ClickButton();
w1.StripMainMenu.Click("File|Save...");
w2 = p1.Window("#32770", "Save Contacts File");
w2.Window("ComboBoxEx32").Window("ComboBox").Window("Edit").Keys("Test.XML");
w2.Window("Button", "&Save").ClickButton();
if(!Files.Compare("Contacts.xml", "C:\\Training\\Test.XML", 0, true))
Log.Error("The files are not identical.");
w2 = w1.WinFormsObject("panel1");
w3 = w2.toolStrip1;
w3.ClickItem("+");
w1.WinFormsObject("dataGridView1").ClickCell(4, "Name");
w3 = w2.textBox1;
w3.Click(52, 5);
w3.Keys("Test");
w3 = w2.textBox2;
w3.Click(53, 11);
w3.Keys("Test");
w2.Click(205, 102);
w3 = w2.textBox3;
w3.Click(52, 7);
w3.Keys("Test");
w1.StripMainMenu.Click("File|Save...");
p1.Window("#32770", "Save Contacts File").Window("Button", "&Save").
ClickButton();
p1.Window("#32770", "Save Contacts File", 1).Window("Button", "&Yes").
ClickButton();
if(!Files.Compare("Contacts.xml", "C:\\Training\\Test.XML", 0, true))
Log.Error("The files are not identical.");
w1.Close();
}
23.Run the new method. The test log will show a file comparison error.
5. Use the finder tool to select the grid from the "StoreSampleProgram"
[JScript]
function Test2()
{
var p1;
var w1;
var w2;
TestedApps.StoresSampleProgram.Run();
p1 = Sys.Process("StoresSampleProgram");
w1 = p1.Form1;
w1.StripMainMenu.Click("File|Open...");
w2 = p1.Window("#32770", "Open Contacts XML");
w2.Window("SHELLDLL_DefView").Window("SysListView32", "FolderView").
ClickItem("Contacts.xml", 0);
w2.Window("Button", "&Open").ClickButton();
if(!Regions.Compare("WinFormsObject_dataGridView",
Sys.Process("StoresSampleProgram").WinFormsObject("Form1").
WinFormsObject("dataGridView1"),false, false, true, 0))
Log.Error("The regions are not identical.");
w1.Close();
}
11.Add the line, see below, before the If in the code.
[VBScript]
Call w1.WinFormsObject("dataGridView1").ClickCell(1, "Name")
[JScript]
w1.WinFormsObject("dataGridView1").ClickCell(1, "Name");
12.Run the method.
[JScript]
function Test3()
{
var p1;
var w1;
var w2;
var w3;
TestedApps.StoresSampleProgram.Run();
p1 = Sys.Process("StoresSampleProgram");
w1 = p1.Form1;
w1.StripMainMenu.Click("File|Open...");
w2 = p1.Window("#32770", "Open Contacts XML");
w3 = w2.Window("SHELLDLL_DefView").Window("SysListView32", "FolderView");
w3.ClickItem("Log", 0);
w3.ClickItem("Contacts.xml", 0);
w2.Window("Button", "&Open").ClickButton();
if(Sys.Process("StoresSampleProgram").WinFormsObject("Form1").
WinFormsObject("dataGridView1").RowCount != 5)
Log.Error("The property value does not equal the template value.");
w1.Close();
}
11.Run the routine.
13.6 Summary
In this section we learned about Region (Images) and how to compare two regions. We learn how
TestComplete compares files. And also how to compare multiple properties of an OnScreen object.
XIV
Data-Driven Testing
Data-Driven Testing 147
14 Data-Driven Testing
14.1 Objectives
This section covers how the Data Driven Testing plug-in consumes various common data types. In this
section you'll learn about:
14.2 Overview
The Data Driven Plug-In (DDT) uses ADO to access different data elements, such a text files, Excel
Spreadsheets, or any ADO compatible database. Once a driver has been initialized, the DDT plug-in
provides a common interface to columns and rows in the data source. These methods/properties are:
· Value: Returns the value of a column based on the column name or index.
· EOF: Indicates if the driver is at the end of the data source.
· DriveMethod: Iterates through all the records of the database, and executes a script routine for each
records.
· Next: Move to the next record in the data source
The DDT plug-in supports the creation of three different types of drivers, CVSDriver, ExcelDriver, and
ADODriver:
· CVSDriver is used to read text file such as comma delimited (default) or tab delimited (using a
schema.ini file). By default the first row is the header information (or column names) for the driver.
Example:
Case,User,Password
1,"admin","admin"
2,"user1","pass1"
· ExcelDriver is used to read an Excel spreadsheet. The first row of the sheet is the header
information for the driver.
· ADODriver is a generic driver to read in ADO compatible data source.
[VBScript]
Sub Test1
Dim p1
Dim w1
Dim w2
Set p1 = Sys.Process("Notepad")
Set w1 = p1.Window("Notepad", "*")
Set w2 = w1.Window("Edit")
w2.VScroll.Pos = 0
Call w2.Click(144, 26)
Call w2.Keys("TestComplete")
End Sub
[JScript]
function Test1()
{
var w1;
w1 = Sys.Process("notepad").Window("Notepad", "*").Window("Edit");
w1.VScroll.Pos = 0;
w1.Click(274, 105);
w1.Keys("TestComplete");
}
We can modify the script to enter in multiple words from an outside data source. In the example below
we create a list of customers from the AdventureWorksDB:
[VBScript]
Dim MyDriver
Sub Main
Dim SQLStatement
Dim ConnectionString
' Start Notepad
TestedApps.Notepad.Run
' Limit to 100 records
SQLStatement = "SELECT TOP (100) CustomerID, FirstName, LastName FROM" & _
" Sales.vIndividualCustomer"
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=AdventureWorks;Data Source=.\SQLExpress"
' Create Driver
Set MyDriver = DDT.ADODriver(ConnectionString,SQLStatement)
' Call Method 100 times
MyDriver.DriveMethod("Unit1.Test1")
End Sub
Sub Test1
Dim p1
Dim w1
Dim w2
Dim KeyStr
Set p1 = Sys.Process("Notepad")
Set w1 = p1.Window("Notepad", "*")
Set w2 = w1.Window("Edit")
w2.VScroll.Pos = 0
' Create String with Customer Information
KeyStr = MyDriver.Value("CustomerID")& "," & _
MyDriver.Value("FirstName")& "," & _
MyDriver.Value("LastName")& "[Enter]"
Call w2.Keys( KeyStr)
End Sub
[JScript]
var MyDriver
function Main()
{
try
{
var SQLStatement;
var ConnectionString;
// Start Notepad
TestedApps.Notepad.Run();
// Limit to 100 records
SQLStatement = "SELECT TOP (100) CustomerID, FirstName, LastName FROM" +
" Sales.vIndividualCustomer";
ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;" +
"Persist Security Info=False;" +
"Initial Catalog=AdventureWorks;Data Source=.\\SQLExpress";
// Create Driver
MyDriver = DDT.ADODriver(ConnectionString,SQLStatement);
// Call Method 100 times
MyDriver.DriveMethod("Unit1.Test1")
}
catch(exception)
{
Log.Error("Exception", exception.description);
}
}
function Test1()
{
var w1;
var KeyStr;
w1 = Sys.Process("notepad").Window("Notepad", "*").Window("Edit");
w1.VScroll.Pos = 0;
w1.Click(274, 105);
KeyStr = MyDriver.Value("CustomerID")+ "," +
MyDriver.Value("FirstName")+ "," +
MyDriver.Value("LastName")+ "[Enter]";
w1.Keys(KeyStr);
}
As you can see there is very little modification of the initial recording needed to make it ready for Data
Driven Testing. Most of the work is in the setup of the driving method. This example illustrated
connecting to a MS SQL database using an ADO Driver.
[JScript]
function Test5()
{
var w1;
var w2;
w1 = Sys.Process("All Pairs Sample").MainForm;
w1.WinFormsObject("trackBar1").wPosition = 10;
w2 = w1.WinFormsObject("comboBox1");
w2.ClickItem("Fair Share");
w1.WinFormsObject("comboBox2").ClickItem("All Stores");
w1.WinFormsObject("checkBox3").ClickButton();
w1.WinFormsObject("button1").ClickButton();
w2.ClickItem("Fair Share");
}
14.Modify the checkbox line to get rid of the call to Click Button() substitute Checked = true. See the
example code snippet below.
[VBScript]
w1.WinFormsObject("checkBox3").Checked = true
[JScript]
w1.WinFormsObject("checkBox3").Checked = true;
15.We now need to create a routine for reading the data file. In the main routine add a new line.
16.Type in "DDT.CSVDriver()"
20.Type in "DDT.CurrentDriver.DriveMethod()".
21.In the parentheses, add “Unit1.Test1”. Your script should now look something like the example
below:
[VBScript]
Sub Main
DDT.CSVDriver(Files.FileNameByName("TestData.txt"))
DDT.CurrentDriver.DriveMethod("Unit1.Test1")
End Sub
[JScript]
function Main()
{
DDT.CSVDriver(Files.FileNameByName("TestData.txt"));
DDT.CurrentDriver.DriveMethod("Unit1.Test1");
}
[JScript]
function Test5()
{
var w1;
var w2;
Log.AppendFolder(DDT.CurrentDriver.Value("case"));
w1 = Sys.Process("All Pairs Sample").MainForm;
w1.WinFormsObject("trackBar1").wPosition =
DDT.CurrentDriver.Value("Iterations");
w2 = w1.WinFormsObject("comboBox1");
w2.ClickItem(DDT.CurrentDriver.Value("Strategy"));
w1.WinFormsObject("comboBox2").ClickItem(DDT.CurrentDriver.Value("Stores"));
w1.WinFormsObject("checkBox3").Checked =
(DDT.CurrentDriver.Value("Greedy") == "Y");
w1.WinFormsObject("button1").ClickButton();
w2.ClickItem("Fair Share");
Log.PopLogFolder();
}
Caution: DO NOT TOUCH THE COMPUTER WHILE THE TEST IN RUNNING. There will be an
unexpected window during the test run that TestComplete will handle.
The test log should look something like the example screenshot below:
14.5 Summary
In this section we learned about how the DDT plug-in works and the different types of drivers. We
learned how to modify a script to get values from the DDT driver.
XV
Event Handling
154 TestComplete Made Easy
15 Event Handling
15.1 Objectives
This section explains how to respond to events that occur during testing. In this section you'll learn
about:
General Events
Name Description
Name Description
OnLoadTestingReq Occurs just before TestComplete send an HTTP request to the tested Web Server.
uest
Name Description
OnGetNextStep Occurs when TestComplete get the information about what the next step is to be
executed
OnStepFailed Occurs when a user click the Fail button in the Step Dialog
OnStepSuccess Occurs when a user click the Success button in the Step Dialog
NetworkSuite Events
Name Desciption
Name Description
Name Description
OnWebBeforeNavi Occurs before Internet Explorer navigates to the specified Web Page
gate
OnWebDownloadC Occurs when the downloading of a web page is completed, failed or halted.
omplete
OnWebPageDownl Occurs after Internet Explorer loads the specified page (or frame)
oaded
15.2.1 OnLogError
One of the most commonly used events, OnLogError can be used to gather addition information about
the state of system when the error occurred. For example:
1. Expand the "Events" Project Item.
2. Double click the "GeneralEvents" Project Item.
3. Add an "OnLogError" handler to your project by clicking the new button next to the OnLogError
event .
[VBScript]
Sub GeneralEvents_OnLogError(Sender, LogParams)
Call Log.Picture(Sys.Desktop,LogParams.Str)
End Sub
[JScript]
function GeneralEvents_OnLogError(Sender, LogParams)
{
Log.Picture(Sys.Desktop,LogParams.Str)
}
TestComplete has default handling for an unexpected window if "Ignore unexpected window" is not
checked:
[JScript]
function Test1()
{
var w1;
var w2;
TestedApps.UnexpectedWindow.Run();
w1 = Sys.Process("UnexpectedWindow").UnexpectedWindow;
w2 = w1.WinFormsObject("numericUpDown1");
w2.Click();
w2.Keys("1[Tab]");
//w1.WinFormsObject("numericUpDown2").WinFormsObject("UpDownEdit", "").
Keys("1");
w1.WinFormsObject("button1").ClickButton();
w1.Close();
}
You will get an unexpected window. This unexpected window contains additional information that
the developer can use to track down the issue. So, we will create a event handler for the
unexpected window that will retrieve this information.
12.Click the new Button next to the OnUnexpectedWindow event in the GeneralEvents Editor.
[VBScript]
Sub GeneralEvents_OnUnexpectedWindow(Sender, Window, LogParams)
Call Log.Message("Additional Error Information", _
Window.WinFormsObject("TextBox", "").Text)
End Sub
[JScript]
function GeneralEvents_OnUnexpectedWindow(Sender, Window, LogParams)
{
Log.Message("Additional Error Information",
Window.WinFormsObject("TextBox", "").Text);
}
15.5 Summary
In this section, we have learned about events and the types of events that TestComplete provides. We
have also learned how to attach script code to events. During this time, we learned about one of the
most important events caused by unexpected windows and different options for handling unexpected
windows.
XVI
Working with Databases
164 TestComplete Made Easy
16.2 ADO
ADO stands for "ActiveX Data Object". ADO allows TestComplete to access and manipulate data in a
variety of data source (mostly databases). TestComplete offers two implementations to access ADO
datasources. One route uses native Microsoft methods, the other through Borland (Codegear) methods.
Microsoft Borland
CreateCommand CreateADOCommand
CreateConnection CreateADOConnection
CreateADODataSet
CreateADOQuery
CreateADOStoredProc
CreateADOTable
One of the hardest parts to using ADO is getting the connection string correct. You can get this
information from the developer of the project you're testing, or look at http://www.connectionstrings.com.
Caution: TestComplete can not use the .NET-only connection string (for example the
SqlConnection for SQL Server 2005).
[VBScript]
Sub Main
' Create a new Connection object
Set AConnection = ADO.CreateConnection
' Note that you can also create an ADO connection using the following code:
' Set AConnection = CreateObject("ADODB.Connection")
End Sub
[JScript]
function Main()
{
try
{
var AConnection, RecSet, Cmd, Prm;
// Create a new Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create an ADO connection using the following code:
// AConnection = new ActiveXObject("ADODB.Connection");
16.3 BDE
BDE stands for Borland Database Engine, is a legacy technology and is no longer supported by Borland.
If for some reason you require connectivity using the BDE, find the latest version at "Borland Database
Engine Developer Support" (http://info.borland.com/devsupport/bde/bdeupdate.html).
In the example we will build the code step-by-step, adding the following features as we go:
[VBScript]
Sub Main
' Create a new Connection object
Set AConnection = ADO.CreateConnection
' Note that you can also create an ADO connection using the following code:
' Set AConnection = CreateObject("ADODB.Connection")
End Sub
[JScript]
function Main()
{
try
{
var AConnection, RecSet, Cmd, Prm;
// Create a new Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create an ADO connection using the following code:
// AConnection = new ActiveXObject("ADODB.Connection");
AConnection.Close();
}
catch(exception)
{
Log.Error("Exception", exception.description);
}
}
AConnection.ConnectionString = _
"Provider=SQLOLEDB.1;Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=AdventureWorks;Data Source=.\SQLExpress"
' Activate the connection
AConnection.Open
' Create a new Command object
Set Cmd = ADO.CreateCommand
' To create an ADO command you can also use the following code:
' Set Cmd = CreateObject("ADODB.Command")
' Specify the connection
Cmd.ActiveConnection = AConnection
' Specify command type and text
Cmd.CommandText =
"SELECT * FROM Sales.SalesOrderDetail AS d INNER JOIN " & _
"Sales.SalesOrderHeader AS h ON d.SalesOrderID = h.SalesOrderID " & _
" WHERE (h.CustomerID = ?)"
Cmd.CommandType = adCmdText
' Create a new parameter
AConnection.Close
End Sub
[JScript]
function Main()
{
try
{
var AConnection, RecSet, Cmd, Prm;
// Create a new Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create an ADO connection using the following code:
// AConnection = new ActiveXObject("ADODB.Connection");
End Sub
[JScript]
function Main()
{
try
{
var AConnection, RecSet, Cmd, Prm;
// Create a new Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create an ADO connection using the following code:
// AConnection = new ActiveXObject("ADODB.Connection");
AConnection.Close();
}
catch(exception)
{
Log.Error("Exception", exception.description);
}
}
Cmd.Parameters.Append(Prm)
AConnection.Close
End Sub
[JScript]
function Main()
{
try
{
var AConnection, RecSet, Cmd, Prm;
// Create a new Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create an ADO connection using the following code:
// AConnection = new ActiveXObject("ADODB.Connection");
AConnection.Close();
}
catch(exception)
{
Log.Error("Exception", exception.description);
}
}
[JScript]
function Main()
{
try
{
var AConnection, RecSet, Cmd, Prm;
// Create a new Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create an ADO connection using the following code:
// AConnection = new ActiveXObject("ADODB.Connection");
AConnection.Close();
}
catch(exception)
{
Log.Error("Exception", exception.description);
}
}
6. Iterate through the result set to total the orders (this could have been done with a single sql query).
[VBScript]
Sub Main
' Create a new Connection object
Set AConnection = ADO.CreateConnection
' Note that you can also create an ADO connection using the following code:
' Set AConnection = CreateObject("ADODB.Connection")
RecSet.MoveNext
WEnd
Log.Message("Total Sales = " ^ Sales)
AConnection.Close
End Sub
[JScript]
function Main()
{
try
{
var AConnection, RecSet, Cmd, Prm;
// Create a new Connection object
AConnection = ADO.CreateConnection();
// Note that you can also create an ADO connection using the following code:
// AConnection = new ActiveXObject("ADODB.Connection");
AConnection.Close();
}
catch(exception)
{
Log.Error("Exception", exception.description);
}
}
16.5 Summary
In this section we discussed options for connecting and manipulating datasources using ADO and BDE.
You learned how to retrieve ADO data for use within your tests.
XVII
Web Page Testing
176 TestComplete Made Easy
· DOM - Document Object Model, the native way that Internet Explorer looks at web pages. The DOM
model creates a very flat tree in the Object Browser. All items on the web page need to be re-read
each time the web page is updated. This is the slowest method for using web pages.
· TAG - All HTML elements are sorted by their TAG value. If a link (<A> HTML tag) gets created, only
the "A" node part of the Object Browser tree gets updated.
· Tree - Treats a web page like a normal application. This model creates a very deep tree for most
web pages. This is the fastest method for using web pages.
· Hybrid - This uses both DOM and Tree. All new recording will use the Tree model, while any old
TestComplete code using the DOM will continue to work.
To set the web page model used for the project:
1. Select the Project Project Item and then click on Properties.
2. Select Open Application | Web Testing.
3. Select the desired Tree model.
· DOM - HTML elements are in the form of Item(index). The index will be either the ID or Name
attribute, if any (with the Identification attribute having priority). If the element does not have either
attribute, TestComplete will assign an index number based on the order the item was created.
· TAG - HTML elements have the same form as DOM but are sorted by type.
· Tree - HTML elements have the form ObjectType(Index), for example: Panel(0) - div element, Image
("Logo.gif") - image element.
...or the checkpoint drop down from the "Tools" toolbar from the main form of TestComplete.
2. Selecting either option displays the Create Web Comparison Checkpoint dialog.
· Compare only tab structure - Only tag names are compared, not attributes, attributes' values
and elements' values.
· Compare only specified tags - Only the selected elements will be compared.
o Compare links - Only A elements are compared (text and attributes of the element are
compare as well).
o Compare images - Only IMG elements are compared.
o Compare input elements - Only INPUT elements are compare.
5. Press the OK button and you will be presented with the Copy Text to Clipboard dialog. The dialog
has the script code that will perform the web page comparison.
Note: In this case the dialog contents will be placed into the clipboard so you can paste into your
script routine. If you do the comparison while recording, TestComplete puts the code in for you
automatically.
Tip: If you have a web page that has dynamically created items, you can set a timeout for the
web comparison to wait for the page to be populated before doing the comparison (default is the
Auto-wait timeout).
2. Selecting either option will display the Create Web Accessibility Checkpoint dialog.
· Check server-side images - Verifies that none of the IMG elements contain SRC attribute with
parameters.
4. Press the OK button and TestComplete will present you with a dialog showing code for the Web
Accessibility Checkpoint.
[VBScript]
Sub NativeFind
Dim PageObj
Dim ProductLink
Set PageObj = Sys.Process("iexplore").
Page("http://www.automatedqa.com/")
Set ProductLink = PageObj.NativeWebObject.Find("title","Products","A")
if ProductLink.Exists Then
ProductLink.Click
End If
End Sub
[JScript]
function NativeFind()
{
var PageObj
var ProductLink
PageObj = Sys.Process("iexplore").Page("http://www.automatedqa.com/")
ProductLink = PageObj.NativeWebObject.Find("title","Products","A")
if (ProductLink.Exists)
ProductLink.Click()
}
The second method to find objects on a web (or any other application), is to use the TestedObject.
Find() method. This method allows you to use multiple properties and values to select a web
element. The example below uses the page object again, not the TestedObject. In this case the
page object is the TestedObject, TestedObject can be any on-screen object. To perform the same
search as above:
[VBScript]
Sub TestedObjFind
Dim PropArray, ValuesArray
Dim PageObj
Dim ProductLink
[JScript]
function ConvertArray(AArray)
{
// Uses the Dictionary object to convert a JScript array
var objDict = Sys.OleObject("Scripting.Dictionary");
objDict.RemoveAll();
for (var j in AArray)
objDict.Add(j, AArray[j]);
return objDict.Items();
}
function TestedObjFind()
{
var PropArray, ValuesArray, ConvertedPropArray, ConvertedValuesArray;
var PageObj;
var ProductLink;
// Converts arrays
ConvertedPropArray = ConvertArray(PropArray);
ConvertedValuesArray = ConvertArray(ValuesArray);
PageObj = Sys.Process("iexplore").Page("http://www.automatedqa.com/")
ProductLink = PageObj.Find(ConvertedPropArray,ConvertedValuesArray,3)
if (ProductLink.Exists)
ProductLink.Click()
}
Note: Notice that the Find() method passes a depth value of 3. The depth value indicates that at
most, TestComplete will search the object tree three levels below the current selected
TestedObject.
Choosing the method to use depends on how far down the object tree you are and how complex a
search you require. If you are using the page object, NativeWebObject.Find() is the fastest. Below
the page object, it will depend on the current depth and how far down you need to search. For more
complex searches, TestedObject.Find() provides more flexibility.
4. Click the Pick Object... button in the Add Text to Script dialog.
5. Use the target icon from the Pick Object dialog to select the right object.
'Original recording:
'Sys.Process("iexplore")
'.Page("http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/
'HoverMenu.aspx")
'.Form("aspnetForm").Panel("master_page").Panel("master_content").
'Panel("master_contentplaceholder").
'Panel(0).Panel("ctl00_SampleContent_up1").Panel(0).
'Table("ctl00_SampleContent_GridView1").
'Cell(0, 0).Panel("ctl00_SampleContent_GridView1_ctl02_Panel9").
'Table(0).Cell(0, 0).
'TextNode("ctl00_SampleContent_GridView1_ctl02_Label1")
Set w1 = Sys.Process("iexplore").Page(_
"http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx")
Call w1.ToURL(_
"http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx")
w1.Form("aspnetForm").Panel("master_page").Panel("master_content").
Panel("master_contentplaceholder").Panel(0).Panel("ctl00_SampleContent_up1").
Panel(0).Table("ctl00_SampleContent_GridView1").Cell(0, 0).
Panel("ctl00_SampleContent_GridView1_ctl02_PopupMenu").Panel(0).Panel(0).
Link("ctl00_SampleContent_GridView1_ctl02_LinkButton1").Click
End Sub
//
Original recording:
Sys.Process("iexplore").
Page("http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/
HoverMenu.aspx").
Form("aspnetForm").Panel("master_page").Panel("master_content").
Panel("master_contentplaceholder").Panel(0).
Panel("ctl00_SampleContent_up1").Panel(0).
Table("ctl00_SampleContent_GridView1").
Cell(0, 0).
Panel("ctl00_SampleContent_GridView1_ctl02_Panel9").
Table(0).Cell(0, 0).
TextNode("ctl00_SampleContent_GridView1_ctl02_Label1")
//
w1 = Sys.Process("iexplore").
Page(
"http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx");
w1.ToURL(
"http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx");
w2 =
w1.Form("aspnetForm").Panel("master_page").Panel("master_content");
w2.Panel("master_contentplaceholder").Panel(0).Panel("ctl00_SampleContent_up1").
Panel(0).Table("ctl00_SampleContent_GridView1").Cell(0, 0).
Panel("ctl00_SampleContent_GridView1_ctl02_PopupMenu"). Panel(0).Panel(0).
Link("ctl00_SampleContent_GridView1_ctl02_LinkButton1").Click();
}
The code above will hover the mouse and allow the menu to be clicked.
Note: With Vista, you need to change the run mode from simple to run as, and run as
administrator.
5. Double Click the Project project item to get the project editor.
6. Click the "Properties" button in the project editor.
7. Select "Open Applications | Web Testing".
8. Select "Tree" for the Tree model.
9. Check the "Mark Page Object a child of the browser process".
[VBScript]
Sub Test1
Dim w1
Dim w2
TestedApps.iexplore.Run
Set w1 = Sys.Process("iexplore").
Page(_
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx")
Call w1.
ToURL(_
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx")
Set w2 = _
w1.Form("form1").Panel("content").Panel("login_position").Table("lgin").Cell(0, 0).
Table(0)
[Jscript]
function Test1()
{
var w1;
var w2;
TestedApps.iexplore.Run();
w1 = Sys.Process("iexplore").
Page(
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx");
w1.ToURL(
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx");
w2 = w1.Form("form1").Panel("content").Panel("login_position").Table("lgin").
Cell(0, 0).Table(0);
w2.Cell(0, 1).Textbox("lgin_UserName").Keys("AFDemo[Tab]");
w2.Cell(1, 1).PasswordBox("lgin_Password").Keys("AFDemo2008!!");
w2.Cell(3, 0).SubmitButton("lgin_LoginButton").Click();
w1.Wait();
w1.Form("frmMain").Panel("mainWrapper").Panel("spltMain").
Table("RAD_SPLITTER_spltMain").
Cell(0, 2).Panel("RAD_SPLITTER_PANE_CONTENT_pnContent").Panel("mc").
Panel("cProject_dvStartPage").Panel("left").Panel("recents").Panel(1).Panel(0).
Link(0).Click();
}
[VBScript]
w1.NativeWebObject.Find("innerText","Sample Project ","A").Click
[JScript]
w1.NativeWebObject.Find("innerText","Sample Project ","A").Click();
[VBScript]
Sub Test3
Dim w1
Dim w2
TestedApps.iexplore.Run
Set w1 = Sys.Process("iexplore").
Page(
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx")
Call w1.
ToURL(
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx")
Set w2 = w1.Form("form1").Panel("content").Panel("login_position").Table("lgin").
Cell(0, 0).Table(0)
Call w2.Cell(0, 1).Textbox("lgin_UserName").Keys("AFDemo[Tab]")
Call w2.Cell(1, 1).PasswordBox("lgin_Password").Keys("AFDemo2008!![Enter]")
'Please wait until download completes:
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx"
w1.Wait
' New Stuff below
Dim PropArray, ValuesArray
' Creates arrays of properties and values
PropArray = CreateVariantArray(0, 1)
ValuesArray = CreateVariantArray(0, 1)
w1.Refresh
w1.Find(PropArray,ValuesArray,100).Click
End Sub
[JScript]
function ConvertArray(AArray)
{
// Uses the Dictionary object to convert a JScript array
var objDict = Sys.OleObject("Scripting.Dictionary");
objDict.RemoveAll();
for (var j in AArray)
objDict.Add(j, AArray[j]);
return objDict.Items();
}
function Test3()
{
var w1;
var w2;
TestedApps.iexplore.Run();
w1 = Sys.Process("iexplore").
Page(
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx");
w1.
ToURL(
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx");
w2 =
w1.Form("form1").Panel("content").Panel("login_position").Table("lgin").Cell(0, 0).
Table(0);
w2.Cell(0, 1).Textbox("lgin_UserName").Keys("AFDemo[Tab]");
w2.Cell(1, 1).PasswordBox("lgin_Password").Keys("AFDemo2008!!");
w2.Cell(3, 0).SubmitButton("lgin_LoginButton").Click();
w1.Wait();
// New Stuff below
// Converts arrays
ConvertedPropArray = ConvertArray(PropArray);
ConvertedValuesArray = ConvertArray(ValuesArray);
w1.Refresh();
w1.Find(ConvertedPropArray,ConvertedValuesArray,100).Click();
}
23.Use the "Map Object from Screen" to map the Password textbox.
24.Click the Yes button in the "Map Object Name" dialog.
25.Click the Skip button on the cell object.
26.Change the name to "txtPassword" and click the OK button.
27.Use the "Map Object from Screen" to map the Log In button.
28.Click the Yes button in the "Map Object Name" dialog.
29.Click the Skip button on the cell object.
30.Change the name to "btnLogin" and click the OK button.
31.Login to ActiveFocus.
32.Use the "Map Object from Screen" to map the "Sample Project" Link under the "Recent Projects"
Area.
33.Click the Yes button in the "Map Object Name" dialog.
34.Click Skip on the Form object.
35.Change the name to "Main" and click the OK button.
36.Press the Skip button until the dialog reads "Object Name Mapping (13/13)"
37.Change the name to "SampleProjectLink".
38.Remove the "Name" property from the "Selected Properties".
39.Add the "innerText" property to the "Selected Properties" from the "Available Properties".
40.Click the Highlight button.
41.Click the OK button.
44.Click the run application button (either IE or Firefox) in the recording toolbar.
47.Stop the recording (Your code may not exactly match below).
End Sub
[JScript]
function Test4()
{
var w1;
var w2;
var w3;
TestedApps.iexplore.Run();
w1 = Aliases.PageAF;
w1.ToURL(
"http://www.activefocus.net/AFDemo/login.aspx?ReturnUrl=%2fAFDemo%2fdefault.aspx");
w2 = w1.loginPanel;
w3 = w2.txtUserName;
w3.Click(17, 8);
w3.Keys("AFDemo[Tab]");
w2.txtPassword.Keys("AFDemo2008!!");
w2.btnLogin.Click();
w1.Main.SampleProjectLink.Click();
}
17.9 Summary
In this section we learned about web page testing, how TestComplete represents web pages in the
Object Browser and how to switch between them. In addition, we learned about the different types of web
checkpoints TestComplete has, and how to use them. The Find methods made it easier for us to deal
with unnamed web elements and the HoverMouse method made it so we could test dynamic HTML
elements.
XVIII
WebServices Testing
WebServices Testing 199
18 WebServices Testing
18.1 Objectives
This section demonstrates how to test a web service. In this section you'll learn:
Log.Message(WebServices.SimpleProjectTracker.HelloWorld());
[VBScript]
Call Log.Message(WebServices.SimpleProjectTracker.HelloWorld)
Using the TestComplete AutoCompletion feature you can import the example Web Service supplied with
the book. The previous example above can be generated using AutoCompletion:
[JScript]
function User()
{
var Result;
var TypeFactory;
//Get the type factory for the web service
TypeFactory = WebServices.SimpleProjectTracker.TypeFactory;
Result = TypeFactory.User;
return Result;
}
[VBScript]
Function User
Dim TypeFactory
'Get the type factory for the web service
Set TypeFactory = WebServices.SimpleProjectTracker.TypeFactory
Set User = TypeFactory.User
End Function
This code creates the User object for use with the Web Service (such as invoking the AddNewUser
method).
5. Paste the generated code into the script editor using either "<ctrl>-V" or the Edit | Paste menu
option.
Now that we have the method to create a User, we can use this method to add a new user to the
database using the Web service. The method we are calling in the Web service is AddNewUser().
[JScript]
function AddAUser()
{
var aUser;
aUser = User();
aUser.Name = "Test";
aUser.Email = "test@test.com";
Log.Message("New User Id is " +
WebServices.SimpleProjectTracker.AddNewUser(aUser));
}
[VBScript]
Sub AddAUser
Dim aUser
Set aUser = User()
aUser.Name = "Test"
aUser.Email = "test@test.com"
Log.Message("New User Id is " &
WebServices.SimpleProjectTracker.AddNewUser(aUser))
End Sub
· Create an XMLCheckpoint project item that stores a baseline copy of a web service’s response.
· Generate script code that calls the web service’s method and checks the result.
You can invoke the wizard when recording a test or at design time:
To display the wizard when recording a test, select Create Web Service Checkpoint from the
Recording toolbar:
To display the wizard at design time, select the Create Web Service Checkpoint from the Tools
toolbar. If this toolbar is hidden, right-click somewhere in the toolbar area and select Tools from the
ensuing context menu:
2. On the "Select Web Service Method" page of the wizard, choose the web service method to be
called.
3. On the "Specify Method Parameters" page, enter the method parameter values. If the parameters
have a simple value type (a string, integer, Boolean and so on), enter its value directly on the page.
Note: To specify complex parameter values (that refer to objects), invoke the special "Complex
Parameter" dialog.
4. On the "Store Expected Response" page of the wizard, specify the XMLCheckpoint project item that
will store the expected response of the web service method.
5. Press "Finish" to close the wizard. TestComplete automatically creates (or updates) the specified
XMLCheckpoint project item and then generates script code that calls the method and compares the
result with the data stored by the project item.
If the checkpoint was created during recording, TestComplete displays the generated code in the
Add Text to Script dialog. Using this dialog you can insert the generated script instructions into the
recorded code.
If the checkpoint was created at design time, TestComplete displays the Copy Text to Clipboard
dialog. Here, the generated code can be copied to the clipboard and then pasted into the script
code.
[VBScript]
Call WebServices.SimpleProjectTracker.AddNewProject(XML.project)
If (Not XML.AddNewProject.Compare(WebServices.SimpleProjectTracker)) Then
Call Log.Error("The AddNewProject method of the SimpleProjectTracker web" _
" service returned an incorrect value.")
End If
[JScript]
WebServices.SimpleProjectTracker.AddNewProject(XML.project);
if(!XML.AddNewProject.Compare(WebServices.SimpleProjectTracker))
Log.Error("The AddNewProject method of the SimpleProjectTracker web" +
" service returned an incorrect value.");
Timeout Settings: The timeout settings are used by TestComplete to close inactive connections to the
web service. The timeout logic works with the connect, receive and send timeout settings in the following
order:
· TestComplete will first make a connection request to the web service. If the web service does not
respond in the time specified by the "Connect" timeout, TestComplete treats the connection as
inactive and raises an exception.
· TestComplete then sends the request to the web service, if the request takes longer than the "Send"
timeout, TestComplete treats the connection as inactive and raises an exception.
· After sending the request, TestComplete waits for a response, if this takes longer than the "Receive"
timeout, TestComplete will treat the connection as inactive and raises an exception.
TestComplete compares two XML documents by moving down the hierarchy of document elements and
comparing each document node. The comparison starts at the root node for each document. The
following steps are performed for each node:
· Finds the "matching" node from each document and compares each of the node values. Nodes are
matched on the baseName, namespaceURI properties as well as node prefix and type.
· Compares node attributes and namespace declarations
· Gets a list of child nodes and performs a comparison.
If the node or any of the child nodes are different, TestComplete will report the differences.
By configuring the Checkpoint Options of a XML checkpoint, the default behavior of the
comparison can be changed.
· Ignore attributes - TestComplete only compares names and values for the XML elements.
· Ignore namespace declarations - TestComplete does not check the namespace attribute of the
XML nodes.
· Ignore prefixes - TestComplete does not check the prefix on the name of the XML node.
· Compare in subtree mode - The comparison results will not include nodes that only exist in the
actual document and not in the stored (expected) document (Good for checking only part of an XML
document).
[VBScript]
Sub GetTask
Dim ReturnValue
Set ReturnValue = WebServices.TrainingWS.GetTaskByID(1)
Log.Message("Task 1 is " & ReturnValue.Name)
End Sub
[JScript]
function GetTask()
{
var ReturnValue;
ReturnValue = WebServices.TrainingWS.GetTaskByID(1);
Log.Message("Task 1 is " + ReturnValue.Name);
}
14.Right-click inside the method just created and select Run Current Routine.
[VBScript]
Function ProjectType
Dim TypeFactory
'Get the type factory for the web service
Set TypeFactory = WebServices.TrainingWS.TypeFactory
Set ProjectType = TypeFactory.Project
End Function
Sub AddProject
Dim Prj
Set Prj = ProjectType
Prj.Name = "TestComplete Training Lab"
Prj.Manager = 1
Prj.DueDate = Date() + 7
Dim ReturnValue
ReturnValue = WebServices.TrainingWS.AddNewProject(Prj)
Log.Message("New Project Id is " & ReturnValue)
End Sub
[JScript]
function ProjectType()
{
var Result;
var TypeFactory;
//Get the type factory for the web service
TypeFactory = WebServices.TrainingWS.TypeFactory;
Result = TypeFactory.Project;
return Result;
}
function AddProject()
{
var Prj;
Prj = ProjectType();
Prj.Name = "TestComplete Training Lab"
Prj.Manager = 1;
Prj.DueDate = Utilities.Date() + 7;
var ReturnValue;
ReturnValue = WebServices.TrainingWS.AddNewProject(Prj);
Log.Message("New Project Id is " + ReturnValue);
}
17.Right Click inside the method just created and select "Run Current Routine"
[VBScript]
Sub CheckPoint1
Call WebServices.TrainingWS.GetProjectByID(1)
If (Not XML.GetProjectByID.Compare(WebServices.TrainingWS)) Then
Call Log.Error(_
"The GetProjectByID method of the TrainingWS web service returned an"_
" incorrect value.")
End If
End Sub
[JScript]
function CheckPoint1()
{
WebServices.TrainingWS.GetProjectByID(1);
if(!XML.GetProjectByID.Compare(WebServices.TrainingWS))
Log.Error(
"The GetProjectByID method of the TrainingWS web service returned an incorrect"+
"value.");
}
11.An error message is displayed in the test log. Expand the details of the XML node in the test log to
see the errors.
12.Double-click the "GetProjectByID" project item of the "Stores | XML" project item.
13.Expand the nodes until the Description and DueDate nodes are shown.
14.Delete the Description and DueDate nodes.
18.7 Summary
In the section we learned how to retrieve information about web services in order to perform web service
testing. We started by testing with a simple web service method using primitive types and worked up to
testing a web service with a complex interface. We also learned how to change the default behavior of
TestComplete for timeouts and about XML checkpoints.
XIX
HTTP Performance Testing
222 TestComplete Made Easy
· Scalability Testing: Do hardware changes to the web server cause change to the performance of
the web application?
· Load Testing: Do the server's change with different number of users?
· Stress Testing: Will enough users cause the web server to crash?
· Load Testing or Stress Testing: At what number of users does the web server break or slow down
too much?
By recording different HTTP tasks, you can create realistic scenarios of user interaction with the web
site.
Note: TestComplete can record traffic against HTTP as well as HTTPS connections.
TestComplete can record both HTTP and HTTPS web traffic and automatically captures these
protocols without any specific proxy setting requirements.
Traffic Transponder
· Cookie handling - Configures how TestComplete handles sending of cookies during playback. See
the cookie handling section below for more information.
· Send timeout - The number of seconds that TestComplete will wait for a acknowledgement from the
web server that a connection has been made.
· Receive times - The number of seconds that TestComplete will wait for a reply from the web server.
· Simulate request to third-party site - If checked, TestComplete will not ask for images or other
information from other sites that the web page might request.
· Store request details - If unchecked, TestComplete will only store the header information and not
the details of a web request.
· Synchronize requests - Forces the order of requests to remain the same as when recording, i.e. get
the web page before the images on the page. Requests can get out of order if network traffic is high.
Recorder
Proxy port: the port TestComplete will listen for http traffic on.
· Do not use cookies - This is the same as disabling cookies in your Internet browser. TestComplete
will ignore all cookies while running the load test.
· Use recorded cookies - Cookies will affect the server response and the server should produce the
same responses as recorded. However, since cookies can have expiration dates, the response may
be an error.
· Use real-time cookies - The default selection, TestComplete will replace the cookies as needed
from the web server responses.
The default for a visually created tests is to set the ClearCookies property of the virtual users to true.
When the ClearCookies property is true, all cookies are automatically recreated. If you want cookies to
be recreated, cookies need to be cleared before starting a load test for virtual users created in script.
19.5 Recording
Recording HTTP traffic is similar to standard recording. One difference - it is easier if you have your
client application (Internet Explorer, Firefox, etc) started, and in the case of web browsers, on the web
page you want to start on. Also, if not using Internet Explorer, you will need to configure TestComplete
as the proxy server for the client application.
Note: It is also a good idea to clear the cache of the web browser you are using before recording.
Tip: If you are planning to modify the recorded HTTP traffic and using 'classic' ASP.NET (using
viewstate), turn off HTTP 1.1 in the web browser before recording. This will prevent the web
server from using HTTP compression, but makes it easier to modify the traffic.
1. Start by clicking the record button in TestComplete. On the recording toolbar, click the "Record an
HTTP task" button.
3. If you are using Internet Explorer and have not setup TestComplete as proxy server, TestComplete
will offer to set itself up as a proxy server, click the Yes button.
Tip: If you are using Internet Explorer 7 and are recording against the localhost, IE will ignore
your proxy server settings. You can get around this problem by adding a period after the
localhost. Example use "http://localhost./loadtesting/LoadTestingDemo.dll?action=newuser"
instead of "http://localhost/loadtesting/LoadTestingDemo.dll?action=newuser". Now just record
your activities as you would normally do.
4. When the recording is done, you will end up with a script for running a load test with one single
virtual user.
[VBScript]
Sub Test1
Dim HTTPTask
Dim VirtualUser
Set HTTPTask = LoadTesting.HTTPTaskByName("Task")
Set VirtualUser = LoadTesting.CreateVirtualUser("VirtualUser1")
Set VirtualUser.Task = HTTPTask
Call VirtualUser.Run("Task")
End Sub
[JScript]
function Test1()
{
var HTTPTask;
var VirtualUser;
HTTPTask = LoadTesting.HTTPTaskByName("Task");
VirtualUser = LoadTesting.CreateVirtualUser("VirtualUser1");
VirtualUser.Task = HTTPTask;
VirtualUser.Run("Task");
}
5. The recorded task will be under the Tasks project item under the LoadTesting project item in the
Project Explorer.
The request page holds the properties of the currently selected requestion in the Connections tree.
The fields of the request header are shown in the table. All of these fields can be modified directly or
in script code. The request method (POST or GET) is shown in the edit box above the fields (note:
the protocol version is also shown). The "Raise Events" option is used to indicate this request will
trigger an OnLoadTestingRequest event during playback. OnLoadTestingRequest will allow
modification of the request before sending to the web server.
The response page shows the properties and contents of the response from the web server for the
selected request. Depending on the Content-Type, TestComplete will show the response content
below the properties grid. For example, an image request will show the image, a SOAP request will
show the SOAP response, etc. Again, the information can be edited here or changed in script code.
The "Raise Events" checkmark will call the OnLoadTestingResponse for the selected request/
response pair.
The green line in graph shows the actual request execution sum, the red line show the total time to
perform all requests. Column heading are:
Select the named group you are interested in and you will get the results of all the test runs for that
group.
[JScript]
function Test1()
{
var HTTPTask
var Request
var VirtualUser
HTTPTask = LoadTesting.HTTPTaskByName("Order")
Request = HTTPTask.Connection(0).Request(0)
Request.Variables.Item("paints") = Math.round(100 * Math.random()) + 1
Request.Variables.Item("pencils") = Math.round(100 * Math.random()) + 1
Request.Variables.Item("albums") = Math.round(100 * Math.random()) + 1
VirtualUser = LoadTesting.CreateVirtualUser("VirtualUser1")
VirtualUser.Task = HTTPTask
VirtualUser.Run("Order")
}
Caution: There is one warning with this method, since you are making a copy of the HTTP task
for each virtual user, it is possible to consume too much memory causing a slow down of the
test.
The Second method is to use the OnLoadTestingRequest event to modify the traffic. To use
OnLoadTestingRequest, first checkmark the raise events on all the request you wish to modify.
[VBScript]
Sub Test1
Dim HTTPTask
Dim VirtualUser
Set HTTPTask = LoadTesting.HTTPTaskByName("Task")
HTTPTask.Connection(0).Request(0).RequestEventTrigger = True
Set VirtualUser = LoadTesting.CreateVirtualUser("VirtualUser1")
Set VirtualUser.Task = HTTPTask
Call VirtualUser.Run("Task")
End Sub
[JScript]
function Test4()
{
var HTTPTask;
var VirtualUser
HTTPTask = LoadTesting.HTTPTaskByName("Order")
HTTPTask.Connection(0).Request(0).RequestEventTrigger = true
VirtualUser = LoadTesting.CreateVirtualUser("VirtualUser1");
VirtualUser.Task = HTTPTask;
VirtualUser.Run("Task");
}
Next, add the OnLoadTestingRequest event handler. Open the editor for Events from the Project
Explorer and click the New button next to the OnLoadTestingRequest in the HTTP LoadTesting
Events category.
Click OK in the New Routine Dialog and add script code to modify the request:
[VBScript]
Sub GeneralEvents_OnLoadTestingRequest(Sender, User, Request)
Request.Variables.Item("paints") = Int(1000 * Rnd()) + 1
Request.Variables.Item("pencils") = Int(1000 * Rnd()) + 1
Request.Variables.Item("albums") = Int(1000 * Rnd()) + 1
End Sub
[JScript]
function GeneralEvents_OnLoadTestingRequest(Sender, User, Request)
{
Request.Variables.Item("paints") = Math.round(100 * Math.random()) + 1
Request.Variables.Item("pencils") = Math.round(100 * Math.random()) + 1
Request.Variables.Item("albums") = Math.round(100 * Math.random()) + 1
}
7. Right-click on the Tests Project Item of the LoadTesting Project Item in the Project Explorer and
Select Add | New Item...
8. Press OK in the Create Project Item Dialog.
9. Create an HTTP Load Testing with five virtual users.
· Add a description "HTTP Lab"
· Add a Result Group "HTTP Lab"
· Make sure that "Run concurrently" is check marked.
· Right-click the white area under virtual users and select New Item from the context menu.
· Change the User Count to 5
· Set the Task to the name of new created task.
· Set the workstation to "Master"
10.Right-click the newly created Test and select Run from the context menu.
11.Examine the newly created test log.
2. In the Events Editor, select OnLoadTestingRequest and click the New button.
[VBScript]
Dim SearchValues
SearchValues = Array("TestComplete","AQtime","Automated Build Studio")
Randomize
[Jscript]
var SearchValues = new Array("TestComplete","AQtime","Automated Build Studio");
5. Right-click on the Test created from the first part of the lab and select Run from the context menu.
6. Examine the Headers for the different user to see the changes in the traffic.
19.11 Summary
In this section, we have learned about HTTP Performance testing and the types of performance testing
such as load, stress and scalability. We have learned how to record HTTP traffic and how to modify the
traffic before sending request to the web server.
XX
Remote Agent
Remote Agent 239
20 Remote Agent
20.1 Objectives
Remote Agent is a tool that allows for the distribution of HTTP loads tests across a network of
computers. In this section you will learn:
During installation, you will be prompted to select which mode you want Remote Agent to use:
Console Mode
When running Remote Agent in console mode you'll see this window on your Windows Desktop:
To exit Remote Agent from this mode simple activate the window by clicking on it and press
Escape.
Service Mode
When Remote Agent is installed in service mode there is no visible UI that will appear. To control
the execution of Remote Agent you need to change the settings under Windows Services. In XP,
you can view Windows Services Window by running the command "services.msc" from the Run
command on the Windows Start menu.
From this window you can right click on TestComplete 6 HTTP Load Testing Remote Agent and
change its Startup Type.
NOTE: In TestComplete 6.3 and later Remote Agent (RA) is implemented as a Distributed COM
(DCOM) server meaning it listens in on the standard Microsoft DCOM port of 135. Additionally,
TestComplete will try to connect to Remote Agent through port 135 as well.
Setting Description
description Any descriptive string concerning the Remote Agent instance on the computer.
· There is a proxy server between the computer where the Remote Agent and the
· There is a proxy server between the Remote Agent computer and the computer
where TestComplete executes.
· If the Remote Agent has direct access to the tested Web site and the
TestComplete computer, you may set this option to 0.
Default value: 0.
proxy host Specifies the proxy server that the Remote Agent uses to connect to the tested Web site
and to the computer where TestComplete runs. This can be either the computer name,
or IP address. This option is ignored if the use proxy option is set to 0.
proxy port Specifies the port which the Remote Agent uses to connect to the proxy server specified
by proxy host. Default value: 8080. This option is ignored if the use proxy option is set to
0.
proxy login Specifies the user name under which you want to connect to the proxy server (if it
requires user authentication).
proxy Specifies the password that confirms the identity of the user under whose name you
password want to connect to the proxy server (if it requires user authentication).
Note: Do not forget to end the RA process (stop its service) before changing its settings and then
restarting RA afterwards.
20.5 Hands on Lab: Working with Remote Agent for HTTP Load Testing
To use Remote Agent you need to setup an HTTP Load Testing project in TestComplete. The Load
Testing project has features that allow you to leverage Remote Agent running on multiple machines for
testing web applications or services.
2. On the Create New Project dialog select HTTP Load Testing and click OK
3. Click the Finish button on the Project Wizard dialog to create your new project
Once created the new project will display the following nodes (based on your TestComplete settings
your project may vary slightly):
The LoadTesting node contains the items of interest for conducting HTTP Load testing. These
nodes are:
· Stations - represents the machines that will be conducting the tests. The Master sub-node
represents the machine that TestComplete is running on.
· Tasks - is the HTTP traffic you’re interested in testing.
· Tests - allows you to assign tasks to various stations for test execution.
Setting up Tasks
The next step is to create the HTTP traffic you want to load test your server with. The easiest way to
produce traffic is using TestComplete’s recording facilities. For HTTP load testing this requires setting
TestComplete to be a proxy for your web browser.
1. Configure Internet explorer to use TestComplete as a proxy allowing it to monitor and record HTTP
traffic. For IE you can do that from the Connections tab of the Internet Options dialog setting the
proxy to localhost on port 9999. For Firefox open the Tools | Options dialog and look on the
Advanced page, under the Network tab.
2. Click the record button on the TestComplete toolbar and once recording begins click the Record an
HTTP Task button (circled in red below):
3. This will bring up the Select Load Testing dialog where you can decide to record a new HTTP traffic
or append it to an existing task.
4. Once you click OK you can begin recording HTTP traffic by simply using your browser.
TestComplete will record the HTTP traffic and add it to the task you specified.
At this point, you're ready to leverage Remote Agent and execute your tests harnessing the power of
your networked machines to HTTP Load Test your web applications.
20.6 Summary
Remote Agent is a tool that allows for the distribution of HTTP loads tests across a network of
computers. With Remote Agent installed a single TestComplete user can quickly and easily harness the
power of a network to provide real world load testing of HTTP based web applications. In addition,
Remote Agent has a small footprint and separate install allowing it to be easily deployed for rapid HTTP
load testing.
XXI
Distributed Testing
Distributed Testing 249
21 Distributed Testing
21.1 Objectives
This section explains how tests are run on several computers at the same time. In this section you'll
learn:
Most of the setup of a distributed test, takes place in the master project. The minimum you need to run
a distributed test is a master project with at least one host machine and at least one task for that host
machine to run.
2. Variables - Using these variables, the computers involved in the test can pass data to each other.
This data can only be of types; string, integer, double or Boolean.
3. Run State - This displays the state of each computer during the test run.
21.3 Hosts
Hosts are the secondary computers involved in the test. Hosts need to have either TestComplete or
TestExecute on them and can be addressed by either name or IP address. The base path is where the
computer will start looking for the project to run the test (not required).
Since firewall and other network communication issues can happen, it is recommend that you verify
the existence of the host. Right-click the workspace to get the context menu and click Verify.
21.4 Jobs/Tasks
Jobs and Tasks are where tests to be run are controlled. A Job consists of one or more host computers
tasks. Each job is run to completion before the next job is run. Under each Job are the Tasks (tests) to
be run on the host computer. Each host computer can only be used once in a job for an active task.
5. Action after run - Determines the action to take after the test completes on the host computer.
6. Tag - A value sent to the host computer at the start of the test.
7. Test - The test to be run. If left blank it will be the project/project suite from the path property.
8. Use previous instance - Controls what to do if TestComplete/TestExecute is already running on the
host computer.
21.5 SynchPoints
SynchPoints delay execution of the test until all computers with that synch point name reach the
synchronization point. When all the computers with a named SynchPoint hit that Synchronize Point,
they will continue on with their test. An example of an effective use for SynchPoints: you want to avoid
where two or more users try to edit the same record at the same time and post the data.
21.6 Setup
[VBScript]
Sub Test1
Dim p1
Dim w1
TestedApps.notepad.Run
Set p1 = Sys.Process("notepad")
Set w1 = p1.Window("Notepad", "*").Window("Edit")
w1.HScroll.Pos = 0
w1.VScroll.Pos = 0
Call w1.Click(135, 29)
Set w1 = p1.Window("Notepad", "*")
Call w1.Window("Edit").Keys("TestComplete Training - Distributed Testing")
w1.Close
p1.Window("#32770", "Notepad").Window("Button", "&No").ClickButton
End Sub
[JScript]
function Test1()
{
var p1
var w1
TestedApps.notepad.Run();
p1 = Sys.Process("notepad");
w1 = p1.Window("Notepad", "*").Window("Edit");
w1.HScroll.Pos = 0;
w1.VScroll.Pos = 0;
w1.Click(135, 29);
w1 = p1.Window("Notepad", "*");
w1.Window("Edit").Keys("TestComplete Training - Distributed Testing");
w1.Close();
p1.Window("#32770", "Notepad").Window("Button", "&No").ClickButton();
}
[VBScript]
Sub Test1
Dim p1
Dim w1
TestedApps.notepad.Run
Set p1 = Sys.Process("notepad")
Set w1 = p1.Window("Notepad", "*").Window("Edit")
w1.HScroll.Pos = 0
w1.VScroll.Pos = 0
Call w1.Click(135, 29)
Set w1 = p1.Window("Notepad", "*")
Call w1.Window("Edit").Keys(NetworkSuite.Variables.Var1)
w1.Close
p1.Window("#32770", "Notepad").Window("Button", "&No").ClickButton
End Sub
[JScript]
function Test1()
{
var p1
var w1
TestedApps.notepad.Run();
p1 = Sys.Process("notepad");
w1 = p1.Window("Notepad", "*").Window("Edit");
w1.HScroll.Pos = 0;
w1.VScroll.Pos = 0;
w1.Click(135, 29);
w1 = p1.Window("Notepad", "*");
w1.Window("Edit").Keys(NetworkSuite.Variables.Var1);
w1.Close();
p1.Window("#32770", "Notepad").Window("Button", "&No").ClickButton();
}
2. Add the variable "Var1" to the master project.
Synchronizing computers
There are times when you want to have one computer wait for another computer to complete at least
part of its task before finishing the first computer's task. For example, you want the consumer's computer
to wait until the bank's computer has processed a debit before the consumer's computer checks it
balance. We will show a couple of ways to synchronize.
Using SyncPoints
1. Modify the test in hosted (slave) project.
[VBScript]
Sub Test1
Dim p1
Dim w1
TestedApps.notepad.Run
Set p1 = Sys.Process("notepad")
Set w1 = p1.Window("Notepad", "*").Window("Edit")
w1.HScroll.Pos = 0
w1.VScroll.Pos = 0
Call w1.Click(135, 29)
Set w1 = p1.Window("Notepad", "*")
Call w1.Window("Edit").Keys(NetworkSuite.Variables.Var1)
Call w1.Window("Edit").Keys("[Enter]")
NetworkSuite.Synchronize("SynchPoint1")
Call w1.Window("Edit").Keys(NetworkSuite.Variables.Var1)
w1.Close
p1.Window("#32770", "Notepad").Window("Button", "&No").ClickButton
End Sub
[JScript]
function Test1()
{
var p1
var w1
TestedApps.notepad.Run();
p1 = Sys.Process("notepad");
w1 = p1.Window("Notepad", "*").Window("Edit");
w1.HScroll.Pos = 0;
w1.VScroll.Pos = 0;
w1.Click(135, 29);
w1 = p1.Window("Notepad", "*");
w1.Window("Edit").Keys(NetworkSuite.Variables.Var1);
w1.Window("Edit").Keys("[Enter]");
NetworkSuite.Synchronize("SynchPoint1");
w1.Close();
2. Right-click the SyncPoints Project Item, select Add | New Item... from the context menu.
3. Hit Enter on the Create Project Item dialog.
4. Create a script in the master project.
[VBScript]
Sub Test1
NetworkSuite.Run(false)
NetworkSuite.WaitForState(ns_Running)
Delay(30000)
NetworkSuite.Variables.Var1 = "Rocks"
NetworkSuite.Synchronize("SynchPoint1")
NetworkSuite.WaitForState(ns_Idle)
End Sub
[JScript]
function Test1()
{
NetworkSuite.Variables.Var1 = "TestComplete";
NetworkSuite.Run(false);
NetworkSuite.WaitForState(ns_Running);
Delay(30000);
NetworkSuite.Variables.Var1 = "Rocks";
NetworkSuite.Synchronize("SynchPoint1");
NetworkSuite.WaitForState(ns_Idle);
}
5. Right-click the SyncPoints Project Item, select Add | New Item... from the context menu.
6. Hit Enter on the Create Project Item dialog.
7. Right-Click in the newly created script and select Run Current Routine from the context menu.
On the hosted computer, "TestComplete" will be typed, followed by a delay and then on a new line
"Rocks" will be typed.
[VBScript]
Sub Test1
Dim p1
Dim w1
TestedApps.notepad.Run
Set p1 = Sys.Process("notepad")
Set w1 = p1.Window("Notepad", "*").Window("Edit")
w1.HScroll.Pos = 0
w1.VScroll.Pos = 0
Call w1.Click(135, 29)
Set w1 = p1.Window("Notepad", "*")
Call w1.Window("Edit").Keys(NetworkSuite.Variables.Var1)
Call w1.Window("Edit").Keys("[Enter]")
NetworkSuite.Variables.Var2 = True
Call NetworkSuite.WaitForNetVarChange("Var2",false)
Call w1.Window("Edit").Keys(NetworkSuite.Variables.Var1)
w1.Close
[JScript]
function Test1()
{
var p1
var w1
TestedApps.notepad.Run();
p1 = Sys.Process("notepad");
w1 = p1.Window("Notepad", "*").Window("Edit");
w1.HScroll.Pos = 0;
w1.VScroll.Pos = 0;
w1.Click(135, 29);
w1 = p1.Window("Notepad", "*");
w1.Window("Edit").Keys(NetworkSuite.Variables.Var1);
w1.Window("Edit").Keys("[Enter]");
NetworkSuite.Variables.Var2 = true;
NetworkSuite.WaitForNetVarChange("Var2",false);
w1.Window("Edit").Keys(NetworkSuite.Variables.Var1);
w1.Close();
p1.Window("#32770", "Notepad").Window("Button", "&No").ClickButton();
}
[JScript]
function Test2()
{
NetworkSuite.Variables.Var1 = "TestComplete";
NetworkSuite.Run(false);
NetworkSuite.WaitForNetVarChange("Var2",true);
NetworkSuite.Variables.Var1 = "Rocks";
NetworkSuite.Variables.Var2 = false;
NetworkSuite.WaitForState(ns_Idle);
}
3. Add the variable "Var2" to the master project in the NetworkSuite project item.
4. Right-click in the newly created script and select Run Current Routine from the context menu.
The hosted computer will do the same things as the SyncPoint demo, but with less delay in the project.
Notice that the hosted computer can pass data back to the master computer.
21.7 Summary
In this section we learned how tests are run on several computers at the same time. We also learned
how to script Distributed Tests using Synchronize Points and Network Suite Variables.
XXII
User Forms
262 TestComplete Made Easy
22 User Forms
22.1 Objectives
This section demonstrates how to create user forms and manipulate them using script: In this section
you'll learn:
22.2 Creating
Creating a user form in TestComplete is very similar to creating a form in most development IDEs
(Visual Studio, Eclipse, Rad Studio). First add the UserForms project Item to the project. The
UserForms project item is a holder (folder) for all the user forms created in the project. The next step is
to add an user form to the project (right-click of the UserForms project item and Add | New Items...". In
our example, we will create a simple user name and password dialog.
The left side of the editor contains the components that can be added to the user form. The middle
is the actual user form. And the right side is where the properties and events are setup.
Components are added by dragging with the mouse and dropping on the form. The components
that we use are TcxTextEdit (from the Editors Category), TcxButton (Buttons Category) and
TcxLabel (Helpers Category). We will two of each.
We will also need to set the properties for all of the components (only changed properties shown):
Property Value
User Form
Height 130
Width 450
cxButton1
Caption OK
Default True
ModalResult mrOK
cxButton2
Cancel True
Caption Cancel
ModelResult mrCancel
cxLabel1
cxLabel2
Caption Password:
Name edtUser
Name edtPassword
Properties.EchoMode eemPassword
22.3 Scripting
Now that we have created a user form, we need to learn how to use the form in a script. There are
two method used to display an user form - Show() and ShowModal(). In our example we will use
ShowModal(), which displays the user form and stops the script from playing until the user answers
the dialog. Note: Show() will continue with the next line in the script code.
[VBScript]
Sub Main
'Fill in the current user name
UserForms.UserNameAndPassword.edtUser.Text = Sys.UserName
if UserForms.UserNameAndPassword.ShowModal = mrCancel Then
Runner.Halt("User Cancelled Test")
end If
Log.Message("User: " & UserForms.UserNameAndPassword.edtUser.Text &_
" Logged in with Password: " &_
UserForms.UserNameAndPassword.edtPassword.Text)
End Sub
[JScript]
function Main()
{
//Fill in the current user name
UserForms.UserNameAndPassword.edtUser.Text = Sys.UserName;
if (UserForms.UserNameAndPassword.ShowModal() == mrCancel)
Runner.Halt("User Cancelled Test");
Log.Message("User: " + UserForms.UserNameAndPassword.edtUser.Text +
" Logged in with Password: " +
UserForms.UserNameAndPassword.edtPassword.Text);
}
22.4 Summary
In this chapter, we learned the basics of creating a user form. Then we learned how to display the form
to the user and get information from the form.
XXIII
Best Practices
266 TestComplete Made Easy
23 Best Practices
23.1 General
The following are general tips and best practices to help you get the most out of TestComplete:
· Record/Playback is a quick and easy way to get automated tests up and running but tend to be
brittle leading to problems when the application changes, etc.
· Use Name Mapping and Aliases whenever possible, it is worth the time to setup.
· Use reusable routines whenever possible.
· Keep routines short (less than a page of code).
· Use meaningful variable names (The default variable names of a recording are not very good
variable names).
XXIV
Cheat Sheet
270 TestComplete Made Easy
24 Cheat Sheet
24.1 Keyboard Shortcuts
Global Shortcuts (keys that work when TestComplete is running even if TestComplete does not have
focus)
Record SHIFT-F1
Stop SHIFT-F2
Run SHIFT-F3
Key Mapping (keys that work when TestComplete has focus, generally in the editors)
Debugging
Run F9 F5 F9
Run to Cursor F4 F4 F4
Project/Units
Cursor movement
Up one line UP UP UP
Delete operations
Miscellaneous
Display context menu ALT-F10 (Code Editor ALT-F10 (Code Editor ALT-F10 (Code Editor
only) only) only)
Bookmarks
Clipboard
this dialog (or you have turned Autocompletion), the code completion dialog can be invoked by press
"CTRL-SPACE"
For method known by TestComplete, you can find out what parameters are needed by the method by
pressing "CTRL-SHIFT-SPACE" inside the parentheses.
Global Shortcuts (keys that work when TestComplete is running even if TestComplete does not have
focus)
Record SHIFT-F1
Stop SHIFT-F2
Run SHIFT-F3
XXV
Professional Offering
278 TestComplete Made Easy
25 Professional Offering
Services
AutomatedQA’s worldwide network of partners can provide your organization with training and services
to help you ramp up more quickly or help with your existing automated testing projects. Go to
www.automatedqa.com/partners to find a partner that fits your needs.
Online Training: For companies that have team members in multiple locations or in situations where
onsite training is not feasible, online training is a great option.
Training Summit: If your team only has a few individuals in need of training, this open-enrollment
option is the most cost effective solution.
your own pace in an innovative environment. This is an inexpensive subscription solution the guys at
Falafel Software know you will love. Check out TestCompleteTV.com for more information.
-B-
BDE 166
-F-
Black Box 42 File Comparison 133
Bookmarks 47 Files 133
Borland 166 Find 183
Breakpoints 50 Finder tool 36
Build 23 Firewall Settings 222
Functional Testing 23
-C-
Call Stack 51
-G-
Checkpoint 129, 133, 136 General Events 154
Copyright © 2008 AutomatedQA Corp. - 1.0 Release
Index 281
-I-
Interbase 166
-O-
Object Browser 33
-Q- TCUnitTest 91
Test Items 266
Test Log 230
QA 23
Test Logs 73
TestComplete 11, 17
-R- TestedApps 68
TestExecute 17
R&D 23 TestRecorder 17
RAM 33 Tests 224
Recording 113, 116, 224 Toolbar 29
Recording Toolbar 114 Training 278
Reflection 43 Tree 176
Region Comparison 129
Regions 129
Regression Testing 23 -U-
Remote Agent 239, 241
Unexpected Windows 157
Remote Agent Port 241
Unit Testing 23, 91, 95
Remote Agent Proxy 241
User Forms 262, 264
Requests 227, 232
Requirements 12
Responses 227, 232
Result Logs 31, 230
-V-
Run As 68 Virtual Users 228
Run Mode 68
-W-
-S- Watch List 53
Scalability Testing 222 Web Accessibility Checkpoint 180
Screen Coordinates 120 Web Comparison Checkpoint 177
script Log 72 Web Page 268
Service mode 239 Web Page Model 176
SetFocus 123 Web Services Options 209
Shortcuts 270, 273, 274 Web Services Testing 199, 204, 211
ShowModal 264 Web Services Testing Dialogs 209
Smoke Test 26 Web Testing 185
Sort 34 WebServices Checkpoint 204
Source Code Control 24 White Box 42
SQL Server 164 White Box Application 43
SQL Server 2005 164 Window Coordinates 120
Stations 224, 243 Windows 11
Stopping 117 WinformsObject 43
Stress Testing 222 WndCaption 36
SynchPoints 253 Workspace 31
WSDL 199
-T-
Tag 176
Copyright © 2008 AutomatedQA Corp. - 1.0 Release
Index 283
-X-
XAML 11
XML Checkpoint 211