Surface Automation - Basic Training
Surface Automation - Basic Training
Surface Automation - Basic Training
The training materials and other documentation (“Training Materials”) provided by Blue Prism as part of the training course are Blue
Prism’s Intellectual Property and Confidential Information. They are to be used only in conjunction with the Blue Prism Software which
is licensed to your company, and the Training Materials are subject to the terms of that license. In addition, Blue Prism hereby grants to
you a personal, revocable, non-transferable and non-exclusive license to use the Training Materials in a non-production and non-
commercial capacity solely for the purpose of training. You can modify or adapt the Training Materials for your internal use to the
extent required to comply with your operational methods, provided that you shall (a) ensure that each copy shall include all copyright
and proprietary notices included in the Training Materials; (b) keep a written record of the location and use of each such copy; and (c)
provide a copy of such record to Blue Prism on request and allow Blue Prism to verify the same from time to time on request.
For the avoidance of doubt, except as permitted by the license or these terms, you cannot (a) copy, translate, reverse engineer, reverse
assemble, modify, adapt, create derivative works of, decompile, merge, separate, disassemble, determine the source code of or
otherwise reduce to binary code or any other human-perceivable form, the whole or any part of the Training Materials; (b) sublease,
lease, assign, sell, sub-license, rent, export, re-export, encumber, permit concurrent use of or otherwise transfer or grant other rights in
the whole or any part of the Training Materials; or (c) provide or otherwise make available the Training Materials in whole or in part in
any form to any person, without prior written consent from Blue Prism.
All trademarks are hereby acknowledged and are used to the benefit of their respective owners.
Blue Prism is not responsible for the content of external websites referenced by this document.
Blue Prism Limited, Centrix House, Crow Lane East, Newton-le-Willows, WA12 9UY, United Kingdom
Registered in England: Reg. No. 4260035. Tel: +44 870 879 3000. Web: www.blueprism.com
This course will cover the basic principles of an integration method called Surface Automation. Surface
Automation is a technique for working with images and although primarily used on thin-client applications, it can
also be applied to any application with a user interface.
The term thin client is used to describe an application that does not run on the local machine and uses a
client/server architecture. A thick client application is one that is installed directly on the local machine, like Blue
Prism itself. Although some consider web applications as thin client, here we are looking at applications that
operate on a remote machine and are presented to the user via some virtualisation software, such as Citrix.
With a thin client, Blue Prism cannot use its normal integration techniques because the target application is virtual
and there is very little that spy modes like Win32 and AA are able to detect. Often it is only the main window of the
virtualisation software that can be spied conventionally. An analogy could be to think of the surface of a thick client
application as having a ‘landscape’ made of buttons, fields, and checkboxes, whereas the surface of a thin client
application is smooth and featureless.
To integrate with a thin client application, we must redefine the application surface as a series of regions.
We will begin by discussing the concept of a region. Below is an imaginary thin client application consisting of a
plain, borderless window with a button in the centre.
If we were to spy this application as a thick client, Win32 and AA mode would ‘see’ the application effectively like
this.
With ‘normal’ spy modes, Blue Prism can only detect features of the local virtualisation application, such as its size
and position, but it is blind to the virtualised elements within. The only local information we have on the remote
application, is the way it looks, i.e. the pixels used to display it to us.
In Surface Automation we create regions in order to divide the image into meaningful sections, to build up an
application model, and to design sequences of interaction. By capturing screenshots from the regions at ‘run time’,
we can extract information about the images, compare them against the ‘design time’ model and make logical
deductions.
In our imaginary thin client, we could model a region of the button text to enable us to check at run time that the
button is present, where it is located, and to direct a mouse click on to it.
• Select the Picture Box element in the usual way with a CTRL and left click. This will open Region Editor.
• In Region Editor you may wish to use the drop-down list on the toolbar to zoom in and make things easier
to see.
• To create a region, select the Region button on the tool bar and draw a box over the button, like below. We
will discuss the border of cross hatching later.
• Load the Exercise 1.1.2a.png file and notice that the OK button is now in a slightly different position.
• In Application Modeller, press Highlight again. The region was still found. Why?
• Return to Region Editor by pressing the Regions button.
• The hatched ‘padding’ defines the area that Application Modeller will search in when trying to locate the
region image.
• Close Region Editor and load the Exercise 1.1.2b.png image. The button is now in a markedly different
location.
• Press Highlight. You should find that the image cannot be found because the button is outside the padding.
• Go back to Region editor and change Position property to Anywhere. We’ll discuss the Relative option
later.
• Observe that the padding is expanded to cover the whole of the parent element.
• Open the Navigate properties and set up a Global Mouse Click Centre action.
• At ‘run time’ Blue Prism will naively assume that an image region is in it’s original ‘design time’ location.
• If it is not, then Blue Prism will look in the Search Padding area until it locates the image’s current position.
The search will spiral out from the ‘design time’ location towards the edge of the padding.
• If the image can’t be found an exception will be raised, much in the same way that a ‘No element found’
error is thrown for other types of element.
• In general, it is recommended to keep the default padding values unless you know the element location is
dynamic. Reducing the padding to zero for a static element won’t improve efficiency because the search
begins in the ‘design time’ location.
The way to handle this in Surface Automation is to make relationships between regions. If you were asked to ‘enter
the billing document number range and press the button’ you would instinctively find the ‘Billing’ area and the
fields and button to the right of the ‘Document No.’ label. Surface Automation takes a similar approach.
• Return to Region Editor and create new region around the Document No. label in the Billing section.
Rename this region as ‘Document Number’.
• Now look back at the Region Editor and you should be able to see a faint arrow indicating the Document
Number region is now related to the Billing region.
What this means is that when BP attempts to find the Document Number region it will first locate its parent, Billing.
• Return to Region Editor and create a new region around the button to the right of the ‘Document No.’
label. Make the region fit quite tightly around the arrow, as show below.
• As before, change the properties of this region so that the Position is ‘Relative’ and the Relative Parent is
Document Number.
• You should now see that there is now another faint line linking the button to the label.
• So now there are 2 levels of hierarchy above the button region - the parent, Document Number and the
grandparent, Billing.
• Open the Exercise 1.2.3.png in Image Loader. Use the Previous and Next buttons to see that it is similar to
the previous image, except that some elements have moved slightly.
• Knowing that billing document number fields and the button are no longer in the same position, try to
Highlight the button region.
• You should see that it is still found - why is this? There are two reasons - the dependencies are anchored on
the grandparent Billing region, which hasn’t moved, and the padding around ‘Document No.’ and the
button are enough to cope with the variance in position.
In reality we would probably not choose the Anywhere location method for the Billing label because it is potentially
uneconomical in terms of computing effort to search the whole screen. Instead the padding option might be more
efficient.
Key Point
• Surface Automation is entirely dependent on the target application being clearly visible. If the application is
minimized or obscured by another window then Surface Automation techniques cannot succeed. This can
be difficult to achieve whilst you are developing your objects, and good tip is to avoid maximizing either the
application or Object Studio, and instead try to arrange them ‘side by side’.
• Go to the region properties on the right and change the Location Method property to Coordinates and the
Retain Image property to False. We will discuss these properties in due course but for now press OK to
close Region Editor.
• Press Highlight and you should see that the OK is highlighted in red.
• Open the Navigate properties and set up a Global Mouse Click Centre action.
• Add a Read stage under the Navigate and set it up to perform Read Image.
• Maximise Object Studio, run the page again and observe the click behaviour. Notice how the mouse just
clicks whatever is covering the region.
• Open the properties of the image Data Item and view the image. Notice how the screenshot is taken from
whatever is covering the region.
• Return Object Studio to its previous size covering part of the desktop.
• Open the Exercise 1.3.3.png image, which is completely white.
• Re-run the page and observe the click behaviour. Notice how the mouse clicks in the same place but this
time there is no OK button in the image.
• Open the properties of the image Data Item and view the image. Notice how the screenshot is taken from
the same place but this time there is no OK button in the image.
This limitation will be familiar to users of Blue Prism versions 4 and 5. Version 6 however brings the image region
which makes Surface Automation easier and more robust.
Key Points
• An image region is also the child of a Win32 element, but has the ability to find a screen entity by locating a
design time image inside a run time search area.
• Best Practice is to always relate a coordinate region to an image region, to minimise the prospect of a ‘false
positive’.
So far, we’ve seen how to direct a mouse click onto an application by locating coordinates or by finding a sub-
image. We’ve also learnt that it’s vital that the application is in clear view for images to be found and for mouse
clicks to land; if the target application is obscured or minimised then Surface Automation is not going to work.
Another input technique available is to use keystrokes and the Global Send Keys method.
Key Point
• Although we can spy the Surface Automation Training application as normal (i.e. using Win32 and AA), for
these exercises we are going to pretend that we can’t and work with it as a thin client application.
• Rename the default ‘Element 1’ to ‘Log In Window’ and spy the application window in Win32 mode.
• Close Application Modeller and add a new Navigate stage to the Action1 page.
• Open the Navigate properties form and drag in the Log In Window element.
• Select the Activate Application action from the drop-down list.
• Enter 0.5 in the ‘Pause After Each Step’ field. This field is used to slow down the execution speed of a
Navigate stage. With some actions, and Activate is one of them, applications do not respond
instantaneously, and it is often necessary to intersperse commands with short pauses.
• Press OK to close the Navigate properties and link up your Start and End stages. Your page should simply
look like this.
• In Blue Prism V6 the use of ‘static’ Wait stages to create pauses after Navigate stages has been reduced by
the introduction of the Pause After Each Step field in the Navigate stage properties.
• Press OK and re-run the page. You should see the User Name field being populated.
• Re-run the page (manually press Backspace to clear the field first) to see the effect of the interval. You
should observe that the keystrokes are entered at a more human-like pace.
Key Point
• In Blue Prism V6 the use of ‘dumb’ Wait stages to create pauses between keystrokes has been reduced by
the introduction of the Interval field in the Global Send Keys and Global Send Key Events actions.
• Create a new element in Application Modeller and spy the window again, but this time with Region mode.
• In Region Editor create a coordinate region that sits just inside the User Name field.
• Back in Object Studio, open the properties of your Navigate stage and add a new line between Activate
Application and Global Send Keys.
• Drag in the region you just created and select the Global Mouse Click Centre action.
• Manually clear both fields in the training application and put the cursor in the Password field.
• Run the page again and you should see that the mouse clicks into the User Name field before the keys are
sent.
• Create another coordinate region for the Password field and then return to Object Studio.
• In your diagram you have the option of adding more lines to the properties of your existing Navigate stage,
or you could add a second Navigate stage to handle the Password field. A single Navigate will not be any
more efficient than two, it’s more a question of diagram presentation. Note that there is no real need to
perform Activate Application twice, once should be enough.
Now let’s imagine that the User Name field is already populated with some text.
• Manually enter the name ‘Denis’ into the User Name field and then click in the Password field.
• Run your page again to see that it ignores the existing User Name text and just adds more. Clearly we need
to guard against this.
• In the Navigate properties, introduce a new row under the Global Mouse Click Centre row.
• Set up a Global Send Keys action as before, but this time use the expression “{HOME}{DELETE 20}” as the
input value. Leave the Interval input empty.
• You should be able to guess what will happen next. Run the page again to find out.
• Although tabbing between fields can work, it is not as robust as clicking into a region that has been
identified via a label. Not only is the tab order of an application susceptible to change, but there is also less
certainty that the cursor will be in the right place when you start to enter a value.
• Re-run the page to see the new user name value pasted in. The choice of whether to use paste or
keystrokes is dependent on the target application and the choice of the Business Object developer.
Key Point
• The Interval input for Global Send Keys must be left blank when sending ‘special’ key instructions like
{HOME} and {DELETE}
Identifying Fonts
We will now return to the Image Loader application to learn how to read image text without using the standard
spying techniques.
• Launch Image Loader and open the Exercise 3.1.1.png image. As you can see, this image is deliberately
simple.
• Create a new region for the first line.
Key Point
• Regions to be used for reading text must have the Location Method property set to ‘Coordinates’. The
default ‘Image’ method makes the ‘design time’ image part of the region’s identity and as such the region
won’t be discovered if the ‘run time’ image is different.
• Still in the region properties, select the Font drop down and then select New -> Identify System Font.
• At this stage you may receive a warning message regarding Font Smoothing.
• Font Smoothing is a Windows setting designed to make fonts easier for people to read by blurring (anti-
aliasing) the edges of text characters. This setting disrupts Character Matching and we need it to be
switched off on all Blue Prism PCs.
• See the Appendix at the end of this document for how to switch off Font Smoothing.
• With Font Smoothing disabled, selecting Identify System Font will open the Identify System Font screen, as
shown below.
• In the Text field, type in the same characters shown in the region, i.e., This is Tahoma 9pt. This tells Blue
Prism what characters we are looking to match.
• Click the Search button.
• As it searches, Blue Prism creates an image of the text value as it would appear using each font, and
compares each image with the region to see if it could be a match.
• Potential fonts are added to the Fonts list and once the search is complete, selecting an item in the Fonts
list will show how the text is rendered in that font.
Key Point
• Automatic search requires a degree of experimentation; it may not yield any results or might produce only
partial matches.
• The target image has been made easy, so you should find that a single match is found, as below.
• Select the Tahoma 9 font and click OK. You can rename the font at this point but in this case, we will simply
accept the default name.
• Run the page and you should see that the text is recognised. Remember that if Image Loader is obscured
by Object Studio or anything else, Surface Automation cannot succeed.
• Run the page again, open the image Data Item and press View to see the run time image that Recognise
text is trying to interpret. You might be able to spot the problem, perhaps the region is incorrectly
positioned.
Key Point
• By looking at the properties of the image Data Item you will be able to see the image taken from the
screen, and this might help you understand the problem.
• Open the Exercise 3.1.4.png image and see that it is a coloured version of the previous image.
• Run the page again to confirm that Recognise Text no longer works. This is because Blue Prism is
anticipating black text but can’t find any.
• Open the first read stage, enter the expression “FF0000” in the Colour input value and press OK.
• Re-run the page and you should see that the first region is now recognised.
• Open the second read stage and enter “0000FF” in the Background Colour input filed and press OK.
• Re-run the page and you should see that the second region is now recognised.
Key Point
• Currently Read stages employ a technical notation for colours, known as hexadecimal, or hex for short.
This isn’t the most user-friendly input mechanism and at the time of writing (October 2017) there are plans
to introduce a colour picker.
• Open the Exercise 3.1.4.png image in Paint 3D and zoom in to about 200%.
• Use the colour picker to select the red text and then press the button to the left of the colour picker.
• Note the Hex field in the Edit Colour dialog box.
• If you don’t have Paint 3D there are many useful resources online.
• Open the Exercise 3.1.6.png image and notice that different fonts have been used.
• Now return to Object Studio, create a new page and press the Reset button, shown below in red. This is to
make the object reload all font definitions from the database.
• Link two Read stages into the new page, and set them up to use Recognise Text on the first two regions.
This time however, populate the Font input field with the name of the appropriate font.
• Run the page and you should see that the first two lines of text are read correctly.
MS Sans Serif 9 is the default font when no font is specified, either in Region Editor or in the Read stage. However,
because the font has not been explicitly defined, Blue Prism does not know how to interpret whitespace. If you go
back to System -> Fonts and press Edit, you will see that a font definition contains a Space Width value.
Font
• This is the name of the font definition the Read stage should use.
• It can be left blank if the region has a font assigned to it in the Region Editor.
• If the region has no font assigned, the Read stage will use the default font.
Colour
• This is the hex code of the foreground colour the Read stage should use.
• It must be left blank if a background colour has been specified.
• If left blank and no background colour is specified, the Read stage will assume the foreground colour to be
black.
Background Colour
• This is the hex code of the background colour the Read stage should use.
• It must be left blank if a foreground colour has been specified.
• It can also be set to “auto” to indicate that the least prevalent colour in the region is the foreground
colour. This is useful if the colour of the text in the region is changeable. Note however it cannot be used if
the text is not rendered in a single colour, e.g. as a gradient colour.
• With the Exercise 3.1.6.png image showing in Image Loader, run the page again. You should see that all
three lines are read, apparently successfully.
• Look again at the Data Items, is everything correct? On the author’s machine the second line is wrongly
interpreted as Ariel, instead of Arial. This an example of the fallibility of OCR.
Key Points
• OCR is heuristic and can result in a ‘false positive’ or a ‘false negative’. An example of a false positive is
when the OCR incorrectly determines that some text value exists on the screen, when in reality it does not.
A false negative is where OCR mistakenly decides that a value does not exist, when in fact it does.
• By contrast Character Matching is deterministic, either there is a 100% match with the font definition or
there is no match.
• Care should always be taken when using any OCR technology. Quality cannot be guaranteed in advance,
and only through large scale testing of your specific use case will you know if the technology is suitable for
your solution. Where possible Recognise Text should always be used instead.
• Open Exercise 4.1.1a.png and then open Exercise 4.1.1b.png in Image Loader.
• Create a region around the red icon and press OK to close Region Editor.
• Select the region element and press Highlight to confirm it can be found.
• Press the Previous button on Image Loader and the press Highlight in Application Modeller. You should see
that the region can no longer be found.
• Go back to Object Studio, create a new page and add a Wait stage.
• Open the Wait stage properties, drag in the region, and select the Check Exists condition.
• OK the properties window and link the Wait stage node to an End stage. Don’t bother with a time out
Exception stage for this exercise.
• Before you run the page, ensure Image loader is not obscured – remember Surface Automation cannot
function unless the target application is clearly visible. Also check that it is the blue image that is on display.
• Open Region Editor and expand the Search Padding property of the region. Increase the Right value to
about 120, so that the cross-hatched padding extends towards the edge of the white area.
• Return to Object Studio and open Exercise 4.1.2.png before re-running your page. You should see that the
increased padding has enabled the red icon to be found in its new location.
Key Point
• The Wait stage searches for images within the confines of the Search Padding area. It looks first in the
original ‘design time’ location and then expands the search outwards.
• Open Exercise 4.1.3.png. Although it looks similar to Exercise 4.1.2.png, the red is a different shade.
• Test that the image is different by re-running your page. You should get a time out.
• Open Region Editor and set the Colour Tolerance property to 50.
• Run the page again and you should find that the Wait stage can find the image again.
• Go back to Exercise 4.1.2.png and check that the page runs with that image too.
Here Blue Prism is deeming any pixels whose RGB values are within 50 units of each other to be the same. In reality
the colour variance will usually be far lower than 50, more like somewhere between 1 and 10. As with all the
exercises so far, the example images have been deliberately simplified to illustrate a point.
Recall that in exercise 1.1.1 you were asked to set the Retain Image property of a coordinate region to False.
• Surface Automation is a technique for working with images. Primarily it is used on thin-clients but it can
also be applied to any application with a user interface.
• Like any other type of integration technique, intelligent Wait stages are essential to producing robust
Business Objects.
• Surface Automation is wholly dependent on the visibility of the target application.
• Input is limited to mouse clicks and keystrokes and, if available, pasting from the clipboard.
• Output is limited to Character Matching, OCR and, if available, copying to the clipboard.
• Character Matching can only work when Font Smoothing is switched off.
• Although very useful, no OCR is 100% reliable.
• Coordinate regions must be used for reading text. Image regions are not suitable because they are used to
compare a ‘design time’ image with a ‘run time’ image.
• With image regions, Wait stages can be used to detect visual changes in application state.
• Version 6 introduces new powerful features such as Search Padding, Relative Positioning and Colour
Tolerance.
• It’s Best Practice to make coordinate regions dependent on an image region. For example, using an image
region for a field label and a related coordinate region for the field.
• To switch off font smoothing in Windows 10, navigate to Control Panel > System and Security > System >
Advanced System Settings > Performance > Settings.
• Select the Visual Effects tab and from the list presented uncheck the Smooth edges of screen fonts option.
Further Reading
• Guide to Reading Text with OCR
• Surface Automation of Terminal Emulators
• Surface Automation - Guide to Modifying Fonts