0% found this document useful (0 votes)
2 views26 pages

T04 Training - Script Testing

The document provides a comprehensive guide on script testing using TestComplete, covering topics such as selecting a scripting language, creating unit files, and calling routines. It also details the use of helper objects, regular expressions, and various methods for working with strings, dates, and numeric values. Additionally, it introduces Cross Browser Testing as a cloud service for running functional web tests across different environments and outlines common tasks for managing test environments.

Uploaded by

Bhuuumika Raj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views26 pages

T04 Training - Script Testing

The document provides a comprehensive guide on script testing using TestComplete, covering topics such as selecting a scripting language, creating unit files, and calling routines. It also details the use of helper objects, regular expressions, and various methods for working with strings, dates, and numeric values. Additionally, it introduces Cross Browser Testing as a cloud service for running functional web tests across different environments and outlines common tasks for managing test environments.

Uploaded by

Bhuuumika Raj
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1

Topic : Script Testing


Contents
1. Selecting the Scripting Language
2. Creating Unit file
3. Creating Routine
4. Calling Routines
5. Calling Project Items From Scripts
6. TestComplete Helper Objects
7. Using Dictionary Object To Address Array Elements With String Indexes
8. Using Regular Expressions in Scripts
9. Working with Strings, Time, Dates, Numeric values.
2
Topic : Script Testing
1. Selecting the Scripting Language
- Select File | New | New Project Suite from the TestComplete main menu
- Select File | New | New Project from the TestComplete main menu.
- Select desired language from the Language drop down
3
Topic : Script Testing
2. Creating Unit file
- Right click item Script under “ProjectSuite>Project>Advanced”
- On context menu click Add>New Item
- Enter the file name and click OK button.
4
Topic : Script Testing
3. Creating Routine
- On right side, write desired function as shown in the script editor.
5
Topic : Script Testing
4. Calling Routine

Calling Routines and Variables Declared with in same Unit


Explains how to call routines and variables that reside in same unit.
6
Topic : Script Testing
4. Calling Routine

Calling Routines and Variables Declared in Another Unit


Explains how to call routines and variables that reside in another unit.
7
Topic : Script Testing
4. Calling Routine
UnitA (contains no references) → UnitB (contains a reference to unitA) → UnitC (contains a reference to unitB)
// [UnitA]
function testProcedure()
{
[Link]("The procedure is run.");
}
// ...

// [UnitB]
//USEUNIT UnitA
// ...

// [UnitC]
//USEUNIT UnitB
function Test2()
{
[Link]();
}
// ...
8
Topic : Script Testing
5. Calling Project Items From Scripts

For each project item TestComplete provides special program objects that let you work with project items from scripts.
For instance, these objects let you execute tests provided by project items, or get project items’ property values.

Examples:
- [Link]();
- [Link](0).Run(1);
- [Link]();
9
Topic : Script Testing
6. TestComplete Helper Objects
TestComplete includes many scripting objects. Some of them provide access to TestComplete project items and settings
from tests; others help with common testing tasks and serve various utility functions.
Provides support for working with Microsoft ActiveX Data Objects (ADO): databases, tables, queries, stored
ADO
procedures, etc.
Provides unified methods for converting between various data types: integer to string, date/time to string, variant
aqConvert
to boolean and so forth.
Provides unified methods for working with date and time values: retrieve current date, add or subtract one
aqDateTime
date/time value from another, compare two dates and so on.
Provides unified methods for obtaining information about the operating system, the TestComplete plugin set and
aqEnvironment
for performing various environment-specific operations.
Provides methods for creating, renaming, copying, deleting files as well as for reading from and writing to text and
aqFile
binary files.
Provides methods to work with the computer’s file system: obtain information about drives, folders and files,
aqFileSystem
change file attributes, construct relative file paths, connect to the network drive.
Provides unified methods for operating objects’ members at run time: call methods, compare properties, check if
aqObject
an object has a specified member.
Allows performing various operations with string values: comparing, concatenating, splitting, searching for a
aqString
substring, replacing occurrences.
10
Topic : Script Testing
6. TestComplete Helper Objects
TestComplete includes many scripting objects. Some of them provide access to TestComplete project items and settings
from tests; others help with common testing tasks and serve various utility functions.

Provides a scripting interface to functionality of AQtime 4.7 or later. Contains methods that let you start AQtime,
AQtimeIntegration
select the desired profiler, start and terminate profiling, generate results and so on.
aqUtils Provides various helper routines like test delay, beep, validate identifier name.
Provides support for working with Borland Database Engine (BDE): retrieve data from databases and tables,
BDE
execute queries and stored procedures.
Contains named constants and helper routines for manipulating various data, display message dialogs or prompt
BuiltIn
for user input. Most of routines of this object are obsolete and replaced with analogs from aqNNN objects.
Allows running the desired application in Debug mode or attaching to a running process and enabling
DbgServices
TestComplete to trace debug events and exceptions that occur in this process.
DebugAgent Provides a scripting interface used to configure Debug Info Agent.
dotNET Provides a scripting interface for calling routines defined in .NET assemblies.
DLL Provides a scripting interface for calling routines from dynamic link libraries.
Makes it possible to use regular expressions in DelphiScript. Also it adds the stopwatch functionality to
HISUtils
TestComplete.
Indicator Provides means for controlling the TestComplete indicator from tests: show, hide, output custom text.
JavaClasses Provides the ability to call routines from Java classes and access Java types and type members.
11
Topic : Script Testing
6. TestComplete Helper Objects
TestComplete includes many scripting objects. Some of them provide access to TestComplete project items and settings
from tests; others help with common testing tasks and serve various utility functions.

ManualTestBuilder Provides the ability to create manual tests from scripts.


Options Provides a scripting interface to TestComplete options.
Provides means for controlling script execution from script. It includes methods that allow you to stop the script
Runner
execution and run routines by their names.
slPacker Provides methods for compressing test results, files and folders from tests.
Utils Provide a scripting interface to various helper objects: Picture, Rect, Point, Timers and other.
Win32API Provides the ability to call Win32 API functions from TestComplete tests.
WMI Provides access to the Windows Management Instrumentation (WMI) functionality from TestComplete tests.
12
Topic : Script Testing
7. Using Dictionary Object To Address Array Elements With String Indexes
Alternative to Namemapping UI objects can be accessed using descriptive programming. From a parent object
following methods can be used to get an UI object or collection of objects.

• FindChild Method
• Find Method
• FindAllChildren Method
• FindId Method
• Find Method
• Child Method
• WaitChild Method

The search is performed in the object hierarchy displayed in the Object Browser panel starting from the testedObj
object and continuing down the hierarchy to the specified depth. The returned collection may include the testObj
object and its child, grandchild or great grandchild objects that match the search conditions.
13
Topic : Script Testing
8. Using Regular Expressions in Scripts
A regular expression is a special text string that describes a search pattern.

TestComplete supports native regular expressions (the ones that are built into scripting language engines) and non-
native regular expressions (its own regular expressions). In different cases, you can use different regular expressions:

• When working with text (when searching for text, replacing it, dividing it into several parts) - use native regular
expressions.

• To specify variable parts of a string property value in FindXXX methods (Find, FindChild, FindEx, FindAll and so on)
and in the WaitProperty method - use non-native regular expressions.

• To specify variable parts of item captions when using ClickItem, SelectItem, wItem and similar methods, you can
use both native and non-native regular expressions.
14
Topic : Script Testing
8. Using Regular Expressions in Scripts
Non-Native Regular Expressions in TestComplete

function main()
{
var notepad, window, dialog, control;
[Link]("[Link]", SW_NORMAL);
notepad = [Link]("notepad");

// Get Notepad's main window by using a regular expression


window = [Link]("WndCaption", "regexp:.* Notepad", 5);

[Link]("Format|Font...");
dialog = [Link]("WndCaption", "Font");

// Specify words that must be in the specified property


// of the desired object by using a regular expression
control = [Link]("wItemList", "regexp:.*Western.*Arabic.*", 5);

// Specify the item to be clicked using a regular expression


[Link]("regexp:.*European$");
}
15
Topic : Script Testing
8. Using Regular Expressions in Scripts

Native Regular Expressions in Scripting Languages

re = /pattern/[flags];
re2 = new RegExp("pattern"[, "flags"]);

re = /gr[ae]y/im;
re2 = new RegExp("gr[ae]y", "im");
16
Topic : Script Testing
8. Working with Strings
Method, Property Description
[Link] Adds a new item to a string list.
[Link] Changes the value of the string list item with the given index.
[Link] Compares two specified strings.
[Link] Concatenates two specified strings.
[Link] Removes an item with the given index from a string list.
[Link] Searches for a substring within the given string. Use this method instead of the obsolete [Link].
[Link] Generates a formatted string.
[Link] Retrieves a single character from the input string.
[Link] Returns the number of characters in a string.
[Link] Returns an individual item from the list passed through the input string.
[Link] Returns the number of items in the string list.
[Link] Inserts one string to another at the specified position.
[Link] Specifies a character used to separate individual values in a list.
[Link] Encloses the specified string in quotes.
[Link] Specifies a symbol used as a quotation mark.
[Link] Removes a number of characters from the input string.
[Link] Replaces all the occurrences of one substring with another substring.
[Link] Retrieves a substring from the input string.
[Link] Converts the specified string to lower case.
[Link] Converts the specified string to upper case.
[Link] Removes spaces and control characters from the specified string.
[Link] Converts a quoted string to an unquoted string.
17
Topic : Script Testing
8. Working with Strings

Method Description

[Link] Converts a currency value to a string using the specified format settings.

[Link] Converts a currency value to a string.

[Link] Converts the given date value to a string using the specified format.

[Link] Converts the given date value to a string.


[Link] Converts a floating-point value to a string.
[Link] Converts the given number into a string.
[Link] Converts the specified string to a currency value.
[Link] Converts the specified string to a date value.
[Link] Converts the specified string to a date/time value.
[Link] Converts the specified string to a floating-point value.
[Link] Converts the specified string to an integer value.
aqConvert.StrToInt64 Converts the specified string to a long integer value.
[Link] Converts the specified string to a time value.
[Link] Converts the specified variant value to a string.
18
Topic : Script Testing
8. Working with Time

Method Description
Adds or subtracts the specified number of hours to (from) the given
AddHours
date.
Adds or subtracts the specified number of minutes to (from) the given
AddMinutes
date.
Adds or subtracts the specified number of seconds to (from) the given
AddSeconds
date.
Adds or subtracts the specified number of days, hours, minutes and
AddTime
seconds to (from) the given date.
Compare Compares two specified date/time values.
GetHours Returns the hours part of the specified time value.
GetMinutes Returns the minutes part of the specified time value.
GetSeconds Returns the seconds part of the specified time value.
Now Returns the current date and time.
SetDateTimeElements Returns the Date variable having the specified date and time portions.
SetSystemDateTime Assigns the specified date and time as the system date and time.
SetTimeElements Returns the Date variable having the specified hour, minute and second.
Time Returns the current time.
TimeInterval Calculates the absolute difference between two date/time values.
19
Topic : Script Testing
8. Working with Dates

Method Description
Adds or subtracts the specified number of days to (from) the given
AddDays
date.
Adds or subtracts the specified number of months to (from) the given
AddMonths
date.
Adds or subtracts the specified number of days, hours, minutes and
AddTime
seconds to (from) the given date.
Compare Compares two specified date/time values.
GetDay Returns the ordinal number of a day in a month.
GetDayOfWeek Returns the day of the week for the specified date.
GetDayOfYear Returns the ordinal number of a day in a year.
GetMonth Returns the month number of the specified date.
GetYear Returns the year number of the specified date.
IsLeapYear Indicates whether the specified year is a leap year.
Now Returns the current date and time.
SetDateElements Returns the Date variable having the specified year, month and day.
SetDateTimeElements Returns the Date variable having the specified date and time portions.
SetSystemDateTime Assigns the specified date and time as the system date and time.
Today Returns the current date.
20
Topic : Script Testing
8. Working with Numeric

Method Description
FloatToStr Converts a floating-point value to a string.
Format Converts a floating-point value to a string using the one of predefined format settings.
IntToStr Converts the given number into a string.
StrToFloat Converts the specified string to a floating-point value.
StrToInt Converts the specified string to an integer value.
StrToInt64 Converts the specified string to a long integer value.
Cross Browser Testing

• CBT is a cloud service that provides environments (various operating systems and web browsers) for running functional
web tests.
• You can connect to the Cross Browser Testing Service from the Environment and run your web tests in its virtual
environments. This can be a good solution if you need to run tests in various web browsers without actually buying
additional software and hardware:
✓ You can test your web application in any web browser and on any operating system that Test Complete supports. In
addition, you can set the screen resolution for your testing environment if you need to.
✓ You do not prepare your testing environments manually. Cross Browser Testing environments are already prepared for running Test
Complete tests.
✓ You do not need to distribute your test projects to remote environments and gather test results from them manually. When you
run your tests in Cross Browser Testing environments, your test projects are copied to environments automatically (and are
deleted after the test run is over). The test results are copied to your local computer and are accumulated in a single project suite
automatically.
✓ Tests in CBT environments run concurrently. You can run multiple tests in multiple environments in parallel that will significantly
decrease your testing time.
✓ Get accumulated test results on one computer (on your machine, from which you run tests).
Environment Manager - Common Tasks

• Add tests
• Add test items
• Create groups
• Rename groups
• Add environments
• Set timeout for tests
• Open test editor quickly
• Enable and disable tests and environments
• Change the item order
• Copy , cut or paste items
• Remove tests , groups or environments
• Open a local connection
• Close a local connection
Environment Manager
Test Result
Working With the Log
Video
• To view the execution recorded for the test run, click a link in the Video column.
Note: The video is limited to 10 minutes. If your test runs longer, the video will contain only the first 10 minutes of
the test.

View the Test Complete log


• To view the Test Complete test log data collected for the run, click a link in the Detailed Log column or on the
Extended Information panel.

Start a live test


• If a test failed or completed with a warning, you can start a live test in the CrossBrowserTesting cloud. This way
you will be able to manually check whether your web application functions properly and whether the error (or
warning) was caused by Test Complete.
• To start a live test, simply click a link in the Live Test column. This will open the Cross Browser Testing web site,
with the pre-selected browser, operating system and screen resolution for the test run. All you have to do is to
check the web application's URL and run the test.
26
Topic : TestComplete Scripting
Assignment:

1. Create new Project Suite with language Javascript


2. Create three Units (Script files)
• Call function of Unit A from Unit C through Unit B
3. Write a code using a [Link] to access an UI Object.
4. Use following objects in your code and understand various methods in each object
1. aqConvert Object
2. aqEnvironment Object
3. aqFile Object
4. aqFileSystem Object
5. aqObject Object
6. aqString Object
7. aqUtils Object

You might also like