White-Core

cavalcadehorehoundΜηχανική

5 Νοε 2013 (πριν από 3 χρόνια και 9 μήνες)

114 εμφανίσεις

White

(Core)

(Please also refer to NDoc documentation

available with the source code and binary
)

Introduction

Microsoft introduced a number of interesting technologies with .NET 3.0 including WPF,
WCF and WF that have generated a lot of noise. But also qu
ietly included what was a
powerful technology, UI Automation (UIA), which slipped under many people’s radar.
UIA is a .NET library that allows you to identify UI controls, get their property values
and manipulate them on Windows platform. It represents a
big step towards having a
usable programmatic interface to the Window’s UI. Prior to UIA one could have used the
Windows Message API, but it dealt with very low level C functions. As one would
expect, functional test automation is a natural way in which su
ch a library can be used.
White does that.


White supports functional testing for Win32, WinForm, WPF and SWT applications.
White also makes use of the Windows Messages where UIA doesn’t provide all the
required support. But these usages are abstracted fro
m the users of white API.


White is built on .NET platform using C#.


Layers







.NET 3 Runtime

UI Automation Library

White Core

Your Programs

Windows operating system

Window
Messages


Objects




Enclosed objects can be retrieved from the enclosed ones.









White Core

Keyboard

Mouse

Application

Window


Button

Textbox

Checkbox

ListView

Table (DataGrid)

ComboBox

ListBox

ToolStrip

Tree

ScrollBars

MenuBar

ProgressBar

Label

Image

Hyperlink

DateTimePicker

RadioButton

Tooltip

StatusStrip

Slider

Spinner

TitleBar

Objects (more detail)



































ListView

ListViewHeader

ListViewColumns

ListViewRows

ListViewCells

ScrollBars

VScrollBar

HScrollBar

ToolBar

Menus

Menus

MenuBar

Menus

Menus

Table (Data Grid)

TableHeader

TableColumns

TableRows

TableCell
s

ScrollBars

VScrollBar

HScrollBar

Tree

TreeNodes

TreeNodes

ScrollBars

VScrollBar

HScrollBar

ComboBox

and ListBox

ListItems

ScrollBars

VScrollBar

HScrollBar

TextBox

ScrollBars

VScrollBar

HScrollBar

Spinner

Slider

Increment
Buttons

Title
Bar

Maximize
Button

Minimize
Button

Restore
Button

Close Button

UIItem identification

Managed UI applications have a mechanism for identifying controls by
specifying them names. These names are available for finding controls
on using UIAutomation API. Name property used while developing
applic
ation show up as AutomationId when using UIA API.

Un managed applications donot have such feature. In these applications
the co
ntrols are usually identified by text

(white terminology)

(name
in UIA terminology).

Getting started

Pre
-
requisites

.NET 3 framew
ork

Get hold of the window

Application

application =
Application
.Launch(
"foo.exe"
);

Window

window = application.GetWindow(
"bar"
,
InitializeOption
.NoCache);


White uses UI Automation API, to find controls on a window
.

UIA
communicates to
displayed

window vi
a window messages.
This find is performed by enumerating all the
controls in a window. This can be slow for windows which has a lot of UIItems. White
supports finding of UIItem based on position.

WithCache

creates a cache of PrimaryUIItems. This option is
no meant to
be used by automation programs.


Finding a UI Item and performing action

Button

button = window.Get<
Button
>(
"save"
);

button.Click();


UIItems are
categorized as

primary and secondary.

Primary items
are
retrieved directly from the window while s
econdary items need to be
accessed from

primary items.

“save” is
AutomationId

of button
.

Finding a UIItem based on SearchCriteria

SearchCriteria

searchCriteria =
SearchCriteria
.ByAutomationId(
"name"
).AndControlType(
typeof
(
TextBox
)).


AndIndex(2);


T
extBox

textBox = (
TextBox
) window.Get(searchCriteria);

textBox.Text =
"Anil"
;


Within a window any UIItem can be identified based on following criteria.

a.
AutomationId

is the programmatic identifier specified by the AppDeveloper
.

In
WinForm and WPF this i
s the name supplied to the control. This is not present for SWT
and Win32 applications.

b.
TestControlType

is the Core UIItem type

(as in Fig 2)
.

c.
ControlType

is the ControlType defined in UIAutomation.

d.
Text

is the additional property defined for acce
ssibility purposes. This property maps to
some attribute on UIItem which is visible on the control. Find the detailed map here:

e. Zero based
Index

of UIItem in case multiple UIItems have same identification based on
other parameters.

Index is measured fro
m top left corner of the window X first and Y
second.


Speed up performance by Position based search

Performance of finding UIItems
(
based on search criteria
)

is proportional to the number
of items on a window. UIItems are found by enumerating over all the

UIItems (sub items)
in a window. Smaller the scope of faster would be search. Position based search is based
on this idea.

White remembers the position of UIItems on a window when you run your program for
the first time and stores it on the file system as

an xml file. In the next run it finds the
UIItems based on the position of UIItem which is very fast because there is only one item
at the point.

The position which is saved in xml file is relative to the window, hence change in
position of window doesn’t

affect position based find. Changes in layout of items in a
window are taken care of by overwriting the position when it changes.


To use this, you need to provide identifier for your windows when you instantiate them.

application.GetWindow(
"SomeTitle"
,
I
nitializeOption
.NoCache.AndIdentifiedBy(
"Login"
))

The identifier should be unique to avoid different windows writing to
same file.

Configuration

White configuration is done in App.config file. You need to setup configSections,
sectionGroup and section. Her
e
is an example of how to do this, with the default values
for them. In case any property value is not specified these values would be used.


<
configSections
>


<
sectionGroup

name
=
"
NUnit
"
>


<
section

name
=
"
TestRunner
"

type
=
"
System.Configuration.Name
ValueSectionHandler
"
/>


<
section

name
=
"
ProgramMode
"

type
=
"
Debug
"
/>


</
sectionGroup
>


<
sectionGroup

name
=
"
White
"
>


<
section

name
=
"
Core
"

type
=
"
System.Configuration.NameValueSectionHandler
"
/>


</
sectionGroup
>


</
configSections
>



<
White
>


<
Core
>


<
add

key
=
"
LogActions
"

value
=
"
false
"

/>


<
add

key
=
"
WorkSessionLocation
"

value
=
"
.
"

/>


<
add

key
=
"
PopupTimeout
"

value
=
"
5000
"

/>


<
add

key
=
"
MouseDelayForTooltip
"

value
=
"
0
"

/>


<
add

key
=
"
SuggestionListTimeout
"

value
=
"
3000
"

/
>


<
add

key
=
"
BusyTimeout
"

value
=
"
5000
"

/>


<
add

key
=
"
WaitBasedOnHouseGlass
"

value
=
"
true
"

/>


<
add

key
=
"
UIAutomationZeroWindowBugTimeout
"

value
=
"
5000
"

/>


<
add

key
=
"
TooltipWaitTime
"

value
=
"
3000
"

/>


</
Core
>


</
White
>


All of these pr
operties can be configured programmatically as well. Sample code which
in order to read/update these values.

The configured values are logged when
you run
white programs.



Console
.WriteLine(
CoreAppXmlConfiguration
.Instance.PopupTimeout);



CoreAppXmlConfiguration
.Instance.TooltipWaitTime = 100;


LogActions=”true” to log every action performed on UIItems

WorkSessionLocation specifies the location for storing UIItem position file

For description of other properties look at the wait hand
ling section

Wait handling

1.
When any action is performed white automatically waits till the window can respond
again to next action.

2. Wait based on presence of hour glass. This can be configured by using
WaitBasedOnHourGlass

property

(default value tru
e)
. This ensures that the test would
wait till the cursor remains
in
hour
-
glass or default
-
and
-
hour
-
glass.


or

3. There are cases where the above two strategy aren’t enough and hence
white

provides
its
own wait mechanism
. In this test program waits unti
l the certain condition matches. As
soon as the condition matches it would return. There is maximum wait duration. This
duration can be configured

by setting
BusyTimeout

property.


There are other places where you need to set the timeout (all in milli seco
nds set to some
defaults).

Property

Description

PopupTimeout

Timeout period for finding a popup

TooltipWaitTime

Maximum duration in within which
tooltip would appear (see tooltip
problem)

SuggestionListTimeout

Timeout period for finding a suggestion lis
t
on a textbox

UIAutomationZeroWindowBugTimeout

Timeout till any window is found
for an application. There is a bug
in UIAutomation because of which it
sometimes doesn’t find windows for
a process


Timeout means the upper time limit of search. White keep
s trying till this time, after
every 100 ms.


UISpy

This is a good tool which you would find useful in order to identify
UIItems on a window. This comes along with the .NET 3 SDK.
UISpy is standalone executable and needs only .NET 3 framework.
Hence if you

do not want to download/install SDK just use the exe
which unfortunately is not downloadable as one.

Focus tracking feature in UISpy is quite fast in
finding details
of
UIItems
.


White.NUnit


Verify/Assert

Both of these perform assertions of some kind. Ve
rify doesn’t cause the test to
immediately fail while assert does that. There are reasons to use both.

Verify can be used when you want to collect all the failures and fail the test in the end.
This makes it easier to fix the problems or report them.

Asser
t should be used when there is no point in continuing with the test if certain
condition is not met.


Other

questions

1.

Would there be support for Web Application testing?

Because there are already a lot of good tools which do this, developing it is not unde
r
consideration at this point of time. Look at Selenium, Sahi, Watir, Watin and Watij
for testing web applications.