W8 November 17, 2004 1:45 PM T EST A UTOMATION USING S CRIPTING L - - PDF document

w8
SMART_READER_LITE
LIVE PREVIEW

W8 November 17, 2004 1:45 PM T EST A UTOMATION USING S CRIPTING L - - PDF document

BIO PRESENTATION SUPPLEMENTAL MATERIALS W8 November 17, 2004 1:45 PM T EST A UTOMATION USING S CRIPTING L ANGUAGES Dion Johnson DiJohn Innovative Consulting International Conference On Software Testing Analysis & Review November 15-19,


slide-1
SLIDE 1

BIO PRESENTATION SUPPLEMENTAL MATERIALS

International Conference On Software Testing Analysis & Review November 15-19, 2004 Anaheim, CA USA

W8

November 17, 2004 1:45 PM

TEST AUTOMATION USING SCRIPTING LANGUAGES

Dion Johnson DiJohn Innovative Consulting

slide-2
SLIDE 2

Dion Johnson

  • Mr. Dion Johnson has 10+ years of experience in providing IT services to both

government and private industry in a manner that has demonstrated expertise in multiple areas of the software development lifecycle. With a Bachelor of Science degree in Electrical Engineering, Mr. Johnson has spent much of his professional career as a consultant, tasked with handling all aspects of the delivery of onsite customer services, particularly in the areas of quality assurance (QA), quality control (QC), software process improvements, and requirements analysis. In addition, Mr. Johnson is also a regular conference speaker, having delivered presentations on several different topics at many conferences over the years. Now, as a leader and consultant for DiJohn Innovative Consulting, Inc., he is helping fulfill the company’s motto of “Making Innovation the Standard”.

slide-3
SLIDE 3

Test Automation Using Scripting Languages

Dion Johnson

dionjohnson@dijohn-ic.com

slide-4
SLIDE 4

2

www.dijohn-ic.com

Introduction

Benefits of Test Automation

Reliable and repeatable Streamlines the test effort Reduces cost of test effort

Up until now, there has been a

huge gap between perceived benefits and attained benefits

Only available to those with costly

commercial tools

Squandered through inefficient

practices (i.e. tools on the shelf and unused functionality)

Scripting offers an alternative

that closes the gap

This presentation uses Internet

Explorer and VBScript in examples

Overview

slide-5
SLIDE 5

3

www.dijohn-ic.com

Introduction

Introduction

Advantages When to Use Scripting

Pre-Implementation

Identify Automation Scope Learn Scripting Basics Become Acquainted With Object Models

Scripting Implementation

Create Directory Structure & Pertinent Parameters Obtain Application Object Properties Create User-defined Functions Create Test Scripts

Overcoming Implementation Hurdles

Agenda

slide-6
SLIDE 6

4

www.dijohn-ic.com

Introduction

  • No licensing – scripting languages

are normally made available with

  • perating systems which leads to:
  • Increased Availability – The use of

the scripts is not limited to the number of licenses purchased

  • Lower costs – The lack of licensing

purchase

  • Only requires a text editor for

developing the scripts (i.e. Notepad)

  • Scripting Language is an industry

standard language as opposed to a vendor created derivative

Advantages

slide-7
SLIDE 7

5

www.dijohn-ic.com

Introduction – When to Use Scripting for Test Automation

Indicators that scripting may be a better option:

A commercial automated test tool is not an option Your organization is uninterested in automation, but

you wish to supplement individual manual test efforts

Small automation scope (few tests, applications,

configurations, simple functionality)

Technical resources are proficient in programming Automated scripts need to be available to large

numbers of people

Cost benefit analysis (commercial vs. scripting)

Consider resource skill level (training costs) Consider development costs (time and effort) Cost of tool Cost of licenses # of licenses

When to Use Scripting

slide-8
SLIDE 8

6

www.dijohn-ic.com

Pre-Implementation

Prior to script development the

following needs to take place:

Obtain an understanding of scripting

basics

Study the appropriate Object Model Overview

slide-9
SLIDE 9

7

www.dijohn-ic.com

Pre-Implementation

Compiled Languages

Compiled at ‘Design Time’ by compiler Requires Integrated Development Environment

(IDE) for development

Scripting Language

Interpreted (Compiled) at ‘Runtime’ by a

scripting engine

Engine is executed by a Script Host (i.e.

Windows Script Host –WSH) by saving the appropriate file with the script language extension (i.e. VBScript has the .vbs extension)

May be developed in plain text editor (i.e.

Notepad)

Learn Scripting Basics – Scripting vs. Compiled Languages

slide-10
SLIDE 10

8

www.dijohn-ic.com

Pre-Implementation

Class/Object

  • A set of properties, methods and events that form a

single, modular unit Method

  • A repeatable set of actions
  • There are two types of methods

Sub procedure – performs a certain action Function Procedure – performs an action, returns a value

  • Executed when called by the script

Event

  • A repeatable set of actions
  • Executed based on a specific user action (mouse-click,

etc.) Collection

  • A collection of data or objects of the same type

Learn Scripting Basics – Object Oriented Concepts

slide-11
SLIDE 11

9

www.dijohn-ic.com

Pre-Implementation

Learn Scripting Basics – Object Oriented Illustration

R Button O Button

Properties Shape Text Shape = Rectangle Text = ‘R Button’ Shape = Oval Text = ‘O Button’ Methods Click

slide-12
SLIDE 12

10

www.dijohn-ic.com

Pre-Implementation

Control flow functions provide

control over the order in which the code is executed

Control flow functions may be

broken down into two categories

Branching Constructs (i.e.

If..Then.Else)

Looping Constructs (i.e.

Do..While, For..Next)

Learn Scripting Basics – Control Flow Functions

slide-13
SLIDE 13

11

www.dijohn-ic.com

Pre-Implementation

Each language may have a different

way of writing similar statements

Learn key statements/methods

relative to test automation (the following example are specific to VBScript)

CreateObject GetElementByID GetElementsByName

Learn Scripting Basics – Language Specific Syntax

slide-14
SLIDE 14

12

www.dijohn-ic.com

Pre-Implementation

What It Is

  • A group of related objects that define an application

and work together to complete a set of related tasks

  • Provides the ability to access and manipulate elements
  • f an application
  • Identifies application objects, along with information

about each object including:

Position in the Hierarchy Properties Collections Methods

How To Use

  • Study the Position, Properties, Collections to determine

how to reference an object

  • Study the Methods to determine how to manipulate an
  • bject

Study Object Model – What It Is & How To Use It

slide-15
SLIDE 15

13

www.dijohn-ic.com

Pre-Implementation

IE browsers use the

DHTML (Dynamic HTML) Object Model

The structure of a

statement that clicks an IE button element would be pressed is (The following is not actual syntax, but rather just the structure of the statement:

window.document.element. click Study Object Model – Browser Object Model Note: ‘*’ Indicates a collection * * * * * * * * * * * * * *

slide-16
SLIDE 16

14

www.dijohn-ic.com

Pre-Implementation

Element Document Window

Study Object Model – Browser Object Model Illustration

slide-17
SLIDE 17

15

www.dijohn-ic.com

Scripting Implementation

Overview

The following steps lead to

automation success via scripting:

Obtain Application Object Properties Developed User-defined Functions Create Tests as Sub-routines

slide-18
SLIDE 18

16

www.dijohn-ic.com

Scripting Implementation

Before writing test script code, object

properties must be gathered

There is no built in mechanism for

learning an application page’s object properties

There are two ways in which this

information may be obtained:

Manually – In the case of a browser, the

information may be obtained by viewing the source

Automatically – Create a user-defined function

that loops through the collection of objects on a page and stores the information in a text file

  • r spreadsheet

Obtain Application Object Properties

slide-19
SLIDE 19

17

www.dijohn-ic.com

Scripting Implementation

Sample Web Page Obtain Application Object Properties

slide-20
SLIDE 20

18

www.dijohn-ic.com

Scripting Implementation

Sample source code Obtain Application Object Properties

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <head> </head> <body> <FORM> <P> <LABEL for="Name">Enter User Name: </LABEL> <INPUT type="text" id="UserName"><BR> <LABEL for="Password">Enter Password: </LABEL> <INPUT type="text" id="Password"><BR> <INPUT type="submit" value="Login" id=”LoginButton> </P> </FORM> </body>

slide-21
SLIDE 21

19

www.dijohn-ic.com

Scripting Implementation

User-Defined Functions

User-defined functions increase script

maintainability through modular, reusable code

Common function categories

Business Functions – Executes primary

application functionality

Navigation Functions – Navigates throughout the

application

Exception Handling Functions – Handles

unexpected application occurrences

Miscellaneous Functions – Miscellaneous actions

Many functions will be application specific,

but there are some common functions to consider when using scripting languages

slide-22
SLIDE 22

20

www.dijohn-ic.com

Scripting Implementation

Business functions are largely composed of

inputs and presses/clicks

The example illustrates VBScript inputs in

the first two statements of the function and a VBScript button press in the third statement of the function

User-Defined Functions – Business Functions

slide-23
SLIDE 23

21

www.dijohn-ic.com

Scripting Implementation

Composed of inputs and presses/clicks In scripting, the navigation functions will also be

responsible for opening the application or connecting to an already open application

Functions based on the following statement are

crucial (in VBScript):

CreateObject(“InternetExplorer.Application”)

User-Defined Functions – Navigation Functions

slide-24
SLIDE 24

22

www.dijohn-ic.com

Scripting Implementation

Types of Errors

Syntax Errors – when a VBScript statement is

written incorrectly

Runtime Errors – when an invalid action is taken Logic Errors – when a valid script (no syntax or

runtime errors) produces an undesirable result

Application Errors – when the application functions

contrary to what’s expected

Logic and Application errors (exception) handling

routines will be application specific

A error/exception handling routines in VBScript

rely heavily on:

The ‘Err’ Object The On Error Resume Next statement

User-Defined Functions – Exception Handling Functions

slide-25
SLIDE 25

23

www.dijohn-ic.com

Scripting Implementation

Miscellaneous functions to consider

when using scripting languages include

Get_Object_Attributes – Automatically

  • btains the object properties of a

screen’s objects

Wait function – Verifies the application

has finished loading the page before continuing

User-Defined Functions – Miscellaneous Functions

slide-26
SLIDE 26

24

www.dijohn-ic.com

Scripting Implementation

Test Scripts will be created by combining

already developed functions

For VBScript, if the function library is in a

separate file from the test script that uses it, the test script will need to use the Execute or ExecuteGlobal function for ‘loading’ those external functions

Create Test Scripts

slide-27
SLIDE 27

25

www.dijohn-ic.com

Scripting Implementation

<Scripting Automation Example>

Implementation Example

slide-28
SLIDE 28

26

www.dijohn-ic.com

Overcoming Scripting Implementation Hurdles

Challenges in locating the desired

documentation

Development environment is not

intuitive.

Requires a relatively higher degree

  • f technical expertise

No built-in mechanism for

identifying an application page’s

  • bject attributes

Hurdles

slide-29
SLIDE 29

27

www.dijohn-ic.com

Overcoming Scripting Implementation Hurdles

Utilize training, tutorials, books and white

papers

Join a users group Get a free or inexpensive Script Editor, or

use an inexpensive compiled language equivalent

Create a custom function that identifies

an application page’s object attributes

AutoX Solutions

slide-30
SLIDE 30

28

www.dijohn-ic.com

No longer is the privilege of automation

confined to a few

Test Automation is at everyone’s finger

tips via scripting languages

Accesses the power of scripting languages

is a matter of:

Learning the application object model Creating user defined functions Creating tests by combining already developed

functions

Summary and Conclusion

slide-31
SLIDE 31

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

1

Test Automation Using Scripting Languages

Dion Johnson DiJohn Innovative Consulting, Inc. dionjohnson@dijohn-ic.com www.dijohn-ic.com

Abstract

Unless you have an automation tool for functional testing, you probably do not have time to execute all the manual tests you should. Even if you have such a tool, you may not have the quantity of licenses necessary for reaching your desired level of efficiency. An alternative is to automate tests using scripting languages, such as VBScript, Ruby, or Perl. Scripting languages are at your fingertips every time you sit in front of your computer and are imbedded in many popular, commercially available automated test tools. With examples using VBScript and Internet Explorer, Dion Johnson reveals a step-by-step approach for creating and implementing automated tests via scripting languages. This eye-opening presentation offers valuable information for all who are truly serious about test automation.

Introduction

Given the tremendous pressure that is placed on test teams to ensure an application is thoroughly tested and as free from high-risk defects as possible, test automation is almost mandatory in today’s software projects. Whether the automation effort is small-scaled, or large scaled – the reaped benefits are pretty clear; automation helps to increase reliability and repeatability of testing, while simultaneously decreasing the total cost of testing over time. Not to mention, it helps to keep test engineers awake and motivated, because nothing puts a person to sleep faster than executing the same batch of manual tests over and over and over and over and over and…. Up until now, however, there has been a huge gap between the perceived benefits of test automation, and the actual benefits that are received. This gap is first represented by two segregated groups of testers: those that can afford automation, and those that can’t. These commercial tools are extremely costly, so the benefits of automation have therefore only been available to those that can fit these tools in their budgets. And what exactly are you paying for when you purchase one of these pricey tools? Well, you’re paying for convenience – the convenience of a lot of functionality, the majority of which you’ll probably never use. This squandered functionality is the second representation of the gap between perceived and received automation benefits. Think about it. Better yet, if you have an automated test tool, check

  • ut its user’s guide to get an idea of all of the functionality and options made available by the tool. Then examine how

much of that functionality you’ve actually ever used. Most people probably use less than 10% of the functionality and/or

  • ptions offered by these tools. Some use 0% because they purchase the tools, just to sit them on the shelf unused.

Please understand that it is not being proposed that we stage a coup to overthrow the third party automation tool vendors. What is being proposed is that widen our range of options. Scripting languages offer an alternative to emptying your pockets on an expensive automated test tool, thereby helping to close the gap between perceived and received automation

  • benefits. Focusing mainly on the VBScript scripting language and Web applications run within the Internet Explorer (IE)

browser, this paper reveals a methodical approach to embarking upon automation using ever present, readily available scripting languages. The Introduction section is continued by describing in more detail the advantages of scripting and finally when to consider using scripting languages for automation. Following the Introduction, this paper is segmented into three main parts: Pre-Implementation, Implementation, and Overcoming Implementation Hurdles. Pre-Implementation describes steps that need to be taken prior to embarking upon automation using scripting languages, while Implementation identifies the steps that are involved in successfully conducting automation using scripting languages. The Overcoming Implementation Hurdles portion of the document is devoted to suggestions for circumventing the road blocks that get in the way when using scripting languages for automation.

Advantages

There are many obvious advantages to using scripting languages for test automation, including:

  • No required licensing/increased availability,
slide-32
SLIDE 32

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

2

  • A simple development environment, and
  • Use of an industry-standard language.

N NO O R RE EQ QU UI IR RE ED D L LI IC CE EN NS SI IN NG G/ /I IN NC CR RE EA AS SE ED D A AV VA AI IL LA AB BI IL LI IT TY Y This may possibly be the most significant advantage to using scripting languages for test automation. Since scripting languages are typically made available with operating systems or provided as free downloads, they are ready for use at

  • anytime. Usage is, therefore, no longer limited by the number of tool licenses, which results in increased availability and a

simultaneous decrease in cost. S SI IM MP PL LE E D DE EV VE EL LO OP PM ME EN NT T E EN NV VI IR RO ON NM ME EN NT T Scripting languages typically don’t require a complex Integrated Development Environment (IDE) – a set of integrated tools for code development. This makes it easy to deal with, because you can usually develop and execute the scripts in a simple text editor (e.g. – Notepad on the Windows platform). I IN ND DU US ST TR RY Y-

  • S

ST TA AN ND DA AR RD D L LA AN NG GU UA AG GE E Scripting languages are typically industry standard languages as opposed to vendor developed derivatives. This is advantageous because there will be plenty of information to support the use of that language, including books, white papers, official and unofficial web sites, and user’s groups.

When to Use Scripting For Test Automation

The use of scripting languages for test automation can be something fun and exciting, and a great resume builder, but at the end of the day, if it’s not economical it’s not worth it. There are several indicators that may be used to signal that scripting languages are worth investigating, including one or more of the following:

  • A Commercial Tool is Not an Option – If a commercial tool is not an option, then scripting is automatically the

way to go. There may be several reasons that a commercial tool is not an option; one reason may be that an

  • rganization can’t afford the expensive commercial tools, or just doesn’t feel that the return on investment

justifies the cost. Another reason may simply be that the organization has no interest at all in automating any tests, and is content with having testing resources continue to perform all tests manually. For what ever reason the organization doesn’t want to purchase an expensive automated test tool, scripting provides another way of automating tests. There may be a decision to implement an official automated test effort using scripting, or if the

  • rganization is uninterested in an official effort, a tester may decide to unofficially supplement some of their

manual testing efforts with automated test scripts using scripting languages.

  • The Automation Scope is Small –If the automator is not very proficient in scripting languages, the amount of

effort for implementing the scripting language approach may be too great to be able to successfully conduct on large scaled automation efforts. If the scope of the automation effort is small (e.g. – small number of tests, simple functionality, etc.), it may be suited for scripting.

  • Technical Resources are Proficient Scripters – When resources are proficient in scripting, it may be a little

easier for them to build and maintain an automated test framework using scripting languages, so the probability

  • f success is increased regardless of the size of the automation scope.
  • Automated Scripts Need Wide Concurrent Availability – Often times a project requires large numbers of

people to create or execute automated scripts, which would require multiple tool licenses. Many commercial automated test tools offer a server or floating license, but this only allows a small finite number of concurrent users of the tool. Scripting offers an alternative to this expensive option. You can either chose to use scripting language automation in lieu of purchasing an expensive automated test tool, or you may choose to use scripting language automation to supplement the automation being conducted with an automated test tool, so that fewer licenses are required. Although these indicators are useful, it is still advisable to perform a cost benefit analysis for determining whether it is more cost effective to rely solely on an expensive commercial automated test tool, or to use scripting languages. If presented with a choice between an expensive automated test tool, or using scripting languages, a cost benefit analysis comparison should be conducted. Items to consider in a cost benefit analysis include:

  • Resource skill level,
  • Script development costs (time and effort),
slide-33
SLIDE 33

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

3

  • Script maintenance costs,
  • Training costs,
  • Cost of tool,
  • Cost of licenses, and
  • # of required licenses.

Scripting starts out with an advantage in that there is no tool cost, or licensing cost associated with its use. It will therefore be a matter of determining whether or not the money saved in tool and license cost is outweighed by increased development, maintenance and training costs. If not, consider scripting as the main approach or a supplemental approach. If it does, you may want to go with the expensive commercial automated test tool. For more information on conducting a cost benefit analysis see Douglas Hoffman’s paper entitled “Cost Benefits Analysis of Test Automation”, which may be located at www.stickyminds.com.

Pre-Implementation

Prior to moving into the scripting language implementation phase, there are some pre-implementation activities that must take place. The automated tester must first understand the basics of scripting languages, specifically the basics of the language that will be used for script development. Additionally, the automator will need to learn the appropriate object model (object models are explained later in this document). This information is introduced in the following sections, but for more information see the VBScript Programmer’s Reference.

Scripting Basics

As just discussed, one of the Pre-Implementation tasks is obtaining an understanding of scripting basics, so this section introduces this basic information. Although titled Scripting Basics, this section is also known as the ‘Miracle Cure for Insomnia’, because you’ll probably be asleep by the second paragraph. Since mostly theoretical information is presented, it is fine if you temporarily skip this information and move along to the Study Object Model section of the paper. References to specific portions of this section are made throughout the document at the times that specific information is needed. S SC CR RI IP PT TI IN NG G V VS S. . C CO OM MP PI IL LE ED D L LA AN NG GU UA AG GE ES S Compilation is the process of converting high-level programming language code into the binary code that is understood by a computer. One difference between scripting languages and compiled languages is in the compilation process. When using a compiled language, such as C or Visual Basic, a programmer writes code, and then executes a program called a compiler which performs the compilation process prior to the code being run. This is known as design time compilation. A scripting language, however, such as VBScript or JavaScript, is compiled much later. After a programmer writes the script code, the code is compiled by a script engine when the script is run, hence the name runtime compilation. Another difference between the two types of languages is in the way code is developed. Compiled languages typically require a relatively complex IDE, while scripting languages are developed and maintained in a simple text editor (e.g. – Notepad). The scripts are executed by a program known as a script host, which is responsible for calling the script engine to compile the scripts at runtime. Before the script file can be executed by the script host, it must be saved with the proper extension (e.g. – ‘.vbs’ if the script file is written in VBScript). The script host used by Windows is known as the Windows Script Host (WSH). O OB BJ JE EC CT T O OR RI IE EN NT TE ED D C CO ON NC CE EP PT TS S Object oriented programming is a type of programming in which programmers can define classes/objects with properties,

  • perations (methods that can be applied to the object), events, and collections.

A class is a template for multiple objects with different features. Properties are simply object variables that may be maintained throughout the life of the object. Methods are repeatable actions that may be called by the script, and there are two types of methods: functions and sub procedures. Functions return values, while sub procedures do not. Events are also repeatable actions, but these actions, unlike methods, are not explicitly called by a script; they are called based on an action performed by a user (e.g. – mouse click, scroll, etc.). A collection is a set of data or objects that are of the same type. To help explain this further, let’s examine the class illustrated in Figure 1.

slide-34
SLIDE 34

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

4 Figure 1: Class, Object, Properties, Methods, Collections Illustration The class in the figure is a Button class, and it has two properties that define the features of all buttons: shape and text. There are two objects (instances of the class) illustrated in the figure, and both have shape and text properties, but the values for shape and text are different for each button object. The first button is rectangular in shape, and has the ‘R Button’ text on it, while the second button is oval in shape, and has the ‘O Button’ text on it. Each button also has a method that can be performed on it, and that is the click method; this means that you can click on the button. The two button objects collectively make up what is called the Buttons collection. This collection provides the capability of referring to each button based on its position in the group. Therefore, Object 1 can be referred to in two ways:

  • By its collection location – Buttons Collection object 1, or
  • Its properties – The button that has a rectangular shape, and reads ‘R Button’.

C CO ON NT TR RO OL L F FL LO OW W F FU UN NC CT TI IO ON NS S Control flow functions control when and if specific lines of code are executed, along with any special order in which those lines may be executed. Control Flow functions may be broken up into two categories: branching constructs (e.g. – if..then..else) and looping constructs (e.g. – do..while, for..next). L LA AN NG GU UA AG GE E S SP PE EC CI IF FI IC C S SY YN NT TA AX X The object oriented concepts and control flow functions identified above are fairly standard for various different programming languages. The syntax used for implementing these elements, however, will be different for each language. Once a scripting language is decided upon, it is necessary to learn the syntax of the specific language. In addition it is necessary to learn the syntax of the language code related to test automation. For example, some key statements in VBScript related to application automation are:

  • CreateObject – Invokes an application and provides the script with control over that application.
  • GetElementByID – References an element by its ID property and provides the script access to the element’s

properties and methods.

  • GetElementByName – References an element by its Name property and provides the script access to the

element’s properties and methods. R Button O Button

Properties

  • Shape
  • Text
  • Shape = Rectangle
  • Text = ‘R Button’
  • Shape = Oval
  • Text = ‘O Button’

Methods

  • Click
slide-35
SLIDE 35

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

5

Study Object Model

The second part of the Pre-Implementation phase is studying the appropriate object model. While it was fine to skip the Scripting Basics section, we don’t want to make a habit of skipping over information! Be sure to read this information, because object models are instrumental in being able to effectively conduct automated testing. W WH HA AT T’ ’S S A AN N O OB BJ JE EC CT T M MO OD DE EL L? ? An object model is simply a group of related objects that define an application, and work together to complete a set of application functions. The object model provides a script with information about an object’s hierarchical position, properties, collections and methods (for more information on objects, properties, collections and methods see the Scripting Basics section). Figure 2 illustrates the object model for an IE browser – the Dynamic HTML (DHTML) object model – and will be used to provide more information on what object models are and how they are used. The items in the diagram with an asterisk are collections, while the other items are regular objects. The key relationships that are the focus of the following discussion are those held among Window, Document and Element (Forms and Frames are also closely related, but are not within the scope of this discussion). Figure 3 provides a physical representation of these objects. The Window object is at the top of the hierarchy, and is represented by the browser window. The Document

  • bject is the page that is actually loaded inside of the browser when navigating to an internet URL (such as www.dijohn-

ic.com/home/home.html). Inside of the Document Object are several Elements, such as the Home button that is illustrated in the Figure 3. Figure 2: DHTML Object Model H HO OW W I IS S A AN N O OB BJ JE EC CT T M MO OD DE EL L U US SE ED D? ? By accessing an application’s object model, a script is able to control and manipulate an application and its elements. It is therefore imperative that the object model hierarchy, objects, object properties, collections, and methods be studied in

  • rder to learn how to properly refer to and perform actions on application elements from automated scripts.

* * * * * * * * * * * * * *

slide-36
SLIDE 36

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

6 Figure 3: Physical Representation of Object Model Figure 2 illustrates the hierarchy of a web page, which makes the browser Window the parent of the HTML Document, while the HTML Document is the parent of the HTML Elements. Understanding this hierarchy makes it possible to properly refer to and perform actions an object in the application. The hierarchy of a statement that refers to an element may resemble the following: Window.Document.Element.Property A statement that performs an action on an element (such as click) may resemble the following: Window.Document.Element.Method Figure 5 reveals how actual VBScript statements with this format look and the parts of the statements are explained as follows:

  • bjScreen = Window object
  • document = Document object
  • getElementByID( ) = Element object
  • value = Element Property
  • click = Element Method

Scripting Implementation

Following the Pre-Implementation phase, the Scripting Implementation steps are similar to the steps for developing an automated test framework with any automated tool. For more information on developing an automated test tool see Dion Johnson’s paper entitled, “Designing an Automated Web Test Environment”. This section will focus on the following steps that are vital in finding any degree of success with scripting language automation:

  • Obtaining application object properties

Window Document Element

slide-37
SLIDE 37

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

7

  • Developing User-defined functions
  • Creating Tests as Sub-routines

Obtaining Application Object Properties

Before writing script code to perform actions on application objects, the properties of those objects must be obtained so that the objects can be properly referred to. Since there is no built in mechanism for automatically obtaining an object’s properties, there are two options for getting this information:

  • Manually
  • Custom automated function

In the case of a browser based application, the view source option may be used to manually obtain object properties. Figure 4: Simple Web Page By viewing the source of the simple web page illustrated in Figure 4, we’ll see the following HTML code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <head> </head> <body> <FORM> <P> <LABEL for="Name">Enter User Name: </LABEL> <INPUT type="text" id="UserName"><BR> <LABEL for="Password">Enter Password: </LABEL> <INPUT type="text" id="Password"><BR> <INPUT type="submit" value="Login" id=”LoginButton> </P> </FORM> </body>

slide-38
SLIDE 38

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

8 This code reveals information about properties that will be used for performing actions on those objects. For example, the HTML code reveals that the ‘Enter User Name’ field has an ID equal to “UserName”. The custom automated function approach for obtaining application object properties will be discussed more in the Miscellaneous Functions subsection of the Developing User-defined Functions section.

Developing User-defined Functions

User-defined functions increase script maintainability through the use of modular, reusable code. Some common function types include:

  • Business Functions – Execute primary application functionality
  • Navigation Functions – Navigate through the application
  • Exception Handling Functions – Handle unexpected occurrences
  • Miscellaneous Functions – Miscellaneous actions that don’t fall into any of the other categories

Many functions may be application specific, but there are some basic functions that need to be considered when using scripting languages for automation. These will be discussed in the following subsection. B BU US SI IN NE ES SS S F FU UN NC CT TI IO ON NS S Business functions are largely composed of inputs and button presses/clicks, and may appear as illustrated in Figure 5. Figure 5: Login Business Function Example This function receives three input parameters:

  • bjScreen – the Window object that was connected to using CreateObject (discussed further in Navigation

Functions section below) or some similar function.

  • Login – text to be entered into the UserName field.
  • Password – text to be entered into the Password field.

The first two statements inside of the function shown in Figure 5 illustrate how to enter a value of an IE browser textbox using VBScript, while the final statement illustrates how to click on an IE browser button. Note that the following statement structures are used: Window.Document.Element.Property and Window.Document.Element.Method These statement structures are discussed in the Pre-Implementation section entitled Study Object Model. (Note: If the application has frames, identifying the Document object may get a little more involved, than illustrated in this document).

slide-39
SLIDE 39

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

9 N NA AV VI IG GA AT TI IO ON N F FU UN NC CT TI IO ON NS S Like Business Functions, Navigation Functions are largely composed of inputs and button presses/clicks. In addition, they will be responsible for opening and/or connecting to already open applications; in VBScript, the CreateObject function is instrumental in carrying this out. One implementation of The CreateObject function is illustrated in Figure 6. Figure 6: Navigation Function Example This function has no arguments, but invokes an IE browser window, navigates to the http://www.dijohn-ic.com website, and makes it visible to the user. Then the function returns the pointer to the screen in a variable, so that the screen may be referenced and manipulated. E EX XC CE EP PT TI IO ON N H HA AN ND DL LI IN NG G F FU UN NC CT TI IO ON NS S VBScripts may encounter four types of errors:

  • Syntax Errors –Errors indicating a script statement is written incorrectly.
  • Run-time Errors –Errors indicating an invalid action has been attempted by the script.
  • Logic Errors – Errors involving a valid script (no syntax or runtime errors) that produces an undesirable result.
  • Application Errors – Errors resulting in the application functioning contrary to that expected.

The primary focuses in this document are syntax and run-time error handling. Logic error and application error handling routines are normally application specific, but much of what is discussed regarding syntax and run-time errors will also apply to logic and application errors, because the later two may eventually result in a run-time error that has to be

  • addressed. The main problem with syntax errors and run-time errors is that in VBScript these errors abruptly stop the

current and subsequent scripts from executing. Syntax errors stop the script before it starts, while run-time errors stop the script upon encountering the offending statement during a run. This can be very inconvenient for automated testing, so there must be a mechanism that will allow errors to be handled in an efficient manner at run-time. The main option offered by VBScript is the Err object, and the ‘On Error Resume Next’ statement. The ‘On Error Resume Next’ statement prevents the script from abruptly terminating, while the Err object provides some useful information about the error that can be used to determine what action should be taken to handle the error. M MI IS SC CE EL LL LA AN NE EO OU US S F FU UN NC CT TI IO ON NS S There are several miscellaneous functions to be considered when using scripting languages, including:

  • Get_Object_Properties
  • Wait

The Get_Object_Properties function provides an automated way of identifying the properties of screen objects, thereby eliminating the need to do so manually (see the Obtaining Application Object Properties section above). By using the forms collection (see the Scripting Basics section for more information on collections) this function can loop through all form elements, and print all desired properties of those elements to a file.

slide-40
SLIDE 40

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

10 The Wait function verifies that an application page has completely finished before attempting to perform further actions.

Creating Test Scripts

By the time you get ready to create test scripts, it should be a matter of combining already created functions with some additional code to perform verification. The Test Script in Figure 7 illustrates how this is done. In the illustration the wait miscellaneous function is defined, followed by the invoke_application navigation function, then the app_login business

  • function. The test is created below the function definitions in the subroutine called Test_Script, and the subroutine has the

following structure: Call to Navigation Function Call to Business Function Call to Miscellaneous Function Screen Verification Code Finally, at the end of the script, the Test_Script subroutine is executed, which then puts all of the functions to work. Figure 7: Simple Test Script

slide-41
SLIDE 41

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

11 This example defines all of the functions in the same file from which they are called. In VBScript, if there is a desire to store the functions in a separate file from the test that calls them, it is necessary to use the Execute or ExecuteGlobal function to ‘load’ or ‘include’ that function for use by the test script. More information on using the Execute and ExecuteGlobal functions may be found at www.msdn.microsoft.com/scripting.

Overcoming Script Implementation Hurdles

As with anything good, there are some hurdles to using scripting languages to consider upfront. These hurdles include:

  • Challenges in locating desired documentation
  • A non-intuitive development environment
  • An increased level of technical expertise is required
  • No mechanism for ‘learning’ objects

This section provides detail on each of these hurdles and delves into how those hurdles may be surmounted

Challenges in Locating Desired Documentation

H HU UR RD DL LE E It is simple to locate documentation for basic scripting tasks, but finding documentation for some of the more complex automation tasks at the precise time that the documentation is needed poses an initial challenge. S SO OL LU UT TI IO ON N The most obvious solutions to this includes obtaining training, using internet tutorials, and familiarizing yourself with available books and white papers specific to your scripting language of choice. By familiarizing yourself with the available information, you’ll have a better idea of where to look when a specific scripting need arises. In addition, it may be useful to join a users group. There are plenty of free and inexpensive users groups that would be able to provide support for your

  • efforts. These users groups often work faster than the support for an expensive automated test tool, because many people

are reading and investigating your request.

A Non-intuitive Development Environment

H HU UR RD DL LE E D DE ES SC CR RI IP PT TI IO ON N This hurdle is related to the advantage of being able to develop scripts in a text editor. While this is an advantage that provides simplicity, it is also a hurdle in that it is not very intuitive. There are no text coloring features that help you to distinguish language keywords and methods from other text. Also, there’s no functionality that provides design time syntax help for adding functions to scripts. S SO OL LU UT TI IO ON N Use a freeware or inexpensive shareware script editor/debugger. For VBScript, Microsoft offers a script debugger at its MSDN website, and you may also be able to locate one at www.download.com.

An Increased Level of Technical Expertise is Required

H HU UR RD DL LE E D DE ES SC CR RI IP PT TI IO ON N Without a higher degree of technical expertise automation efforts probably won’t enjoy much long term success regardless

  • f whether test automators use an expensive commercial tool or the scripting language automation approach. The

advantage that is offered by the more expensive automated test tools, however, is that they provide features that will allow short term automation success with a limited degree of technical expertise, and will reduce the automated test tool learning

  • curve. These include the Record & Playback, and built in error handling features. Automation using scripting languages,
  • n the contrary, require a higher degree of technical expertise for both short term and long term success.
slide-42
SLIDE 42

DiJohn Innovative Consulting, Inc. www.dijohn-ic.com Test Automation Using Scripting Languages

12 S SO OL LU UT TI IO ON N The initial answer to this is the same as that provided in the Challenges in Locating Desired Documentation section. There is another option, however, and that is a tool called AutoX. AutoX is a lower cost alternative to expensive automated test

  • tools. Built around the VBScript technology this tool provides many of the conveniences that help to ensure faster

automation success with a lower degree of technical expertise. One of these features is Record & Playback, which makes AutoX the only low cost tool of its kind to offer this functionality for Internet applications. For more information visit the http://www.dijohn-ic.com/Download/Downloads.html website.

No Mechanism for ‘Learning’ Objects

H HU UR RD DL LE E D DE ES SC CR RI IP PT TI IO ON N Scripting languages have no built in mechanism for learning application objects. Commercial tools provide an automatic way of identifying properties of objects that are being acted upon in an automated test script. When using scripting languages, you either have to have prior knowledge of the object from the application’s object model, or in the case of an Internet application you’ll need to check the source code to get the object properties. S SO OL LU UT TI IO ON N One solution for this involves creating a custom function for learning application objects, which is discussed in the section

  • f this document entitled Developing User-defined Functions. The second solution to this is AutoX. AutoX provides a

feature that identifies and stores object properties in an object map.

Conclusion & Summary

Automation through scripting languages presents some hurdles to overcome but at the same time has several advantages. There will never be a world in which expensive automated test tools aren’t used, because these tools provide a level of convenience and dependability that is often worth the price. What this paper is proposing, however, is that we the testers

  • f the world be allowed to make the decision of whether or not an expensive automated test tool is the best approach,

rather than having that decision made for us. Scripting language automation provides us with additional options; options that help us to close the gap between perceived and received automation benefits and that help us to reach the goal for which all of us in the IT world strive for… a more quality product.

Bibliography

Johnson, Dion. “Designing an Automated Web Test Environment”. 2001 www.stickyminds.com Clark, Susanne. VBScript Programmer’s Reference. Indianapolis: Wiley Publishing, Inc, 2003